compression - Compressing a directory of files with PHP -


I am creating a PHP backup script which will dump everything from a database and save it in the file. I have been successful in doing this but now I have to take hundreds of images in a directory and have to be included in a simple .tar.gz file.

What is the best way to do this and how is it done? I have no idea where to start.

If you are using PHP 5.2 or later, Then you use

and then do something on the lines of this:

  $ images_dir = '/ path / to / images'; // This folder should be able to write by server $ backup = '/ path / to / backup'; $ Zip_file = $ backup '/ Backup.zip'; If ($ handle = opendir ($ images_dir)) {$ zip = new ziparchive (); If ($ zip-> open ($ zip_file, ZIPARCHIVE :: CREATE)! == TRUE) {exit ("can not open & lt; $ zip_file»; \ n "); } While (wrong! == ($ file = readdir ($ handle))) {$ zip- & gt; AddFile ($ images_dir. '/'. $ File); Echo "$ file \ n"; } Close ($ handle); Echo "numfiles:". $ Zip- & gt; Number files "\ N"; Echo "status:" $ zip-> Status "\ N"; $ Zip- & gt; near (); Copy 'zip file:'. $ Zip_file "\ N"; }  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -