NameSilo

Zipping Files in a Directory with PHP?

Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
Watch
Impact
149
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
Thanks for your help, we'll see how that goes! :)
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back