views:

132

answers:

3

I'm trying to write a script that allows an admin of a photo uploading system download all their photos at once. Currently I am using

system('zip -r '.$_SERVER['DOCUMENT_ROOT'].'/zip.zip '.$_SERVER['DOCUMENT_ROOT'].'/images/photo-uploads';

to zip the files but this seems to echo names and locations all the files onto the page. Is there anyway to get around this? If not what is the best way to zip files on server.

+1  A: 

You might use exec('zip -r '.$_SERVER['DOCUMENT_ROOT'].'/zip.zip '.$_SERVER['DOCUMENT_ROOT'].'/images/photo-uploads'); instead.

Myles
This way you can also check the results of the system call.
notJim
A: 

You can also use output buffering:

ob_start();
system('zip -r '.$_SERVER['DOCUMENT_ROOT'].'/zip.zip '.$_SERVER['DOCUMENT_ROOT'].'/images/photo-uploads';
ob_end_clean();

This will stop any output from being shown from the system command.

Luu
That is great to do if you need to use the output of the system call somehow, but it this case it sounds like he wants to suppress it.
Myles
+2  A: 

You can use ZipArchive extension instead (if you are allowed to) of calling system zip like that, because it makes your code non-portable.

ghostdog74
Using ZipArchive is the best solution if at all possible, IMO.
notJim