Dynadot โ€” .com Registration $8.99

Zipping Files in a Directory with PHP?

Spacemail by SpaceshipSpacemail by Spaceship
Watch
Hello,

I have a directory of files that I sometimes update by uploading new files to it. I was looking for a way to run a PHP script that will take all the files in that directory and automatically zip them upon running the script. I was also considering learning how to create a cron job to do this, but I have no experience with cron jobs.

I'm not exactly sure what I'd search for to get what I'm looking for, so I was hoping someone here could shed some light on this issue for me. Any help would be very appreciated. :)

Thanks,
Steve
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
If your scripts are running on linux system, try this:
Code:
<?
exec("tar czf dir.tar.gz /dir");
?>
/dir is your directory.

To untar the archive, run this:
Code:
<?
exec("tar -zxvf dir.tar.gz");
?>

I use this method to make backups of my files, then I send everything to other server.

However, some webhosts have exec() command dissabled in their servers for security reasons.

Also, check this link:
http://php.net/zip


It should be easy to set up CronJob/CronTab if your host is running any of popular webhosting control panels (cPanel, Plesk, DirectAdmin...). You can do it easily in "Cron Job" or "CronTab" section in your control panel.
 
Last edited:
1
•••
Thanks for your help, we'll see how that goes! :)
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back