Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top