//Get the directory to zip
$filename_no_ext=$_GET['directtozip'];
// we deliver a zip file
header("Content-Type: archive/zip");
// filename for the browser to save the zip file
header("Content-Disposition: attachment; filename=$filename_no_ext".".zip");
// get a tmp name for the .zip
$tmp_zip = tempnam ("tmp", "tempname") . ".zip";
//change directory so the zip file doesnt have a tree structure in it.
chdir('uploads/'.$_GET['directtozip']);
// zip the stuff (dir and all in there) into the tmp_zip file
exec('zip '.$tmp_zip.' *');
// calc the length of the zip. it is needed for the progress bar of the browser
header('Content-Length: ' . filesize($file));
// deliver the zip file
$fp = fopen("$tmp_zip","r");
echo fpassthru($fp);
// clean up the tmp zip file
unlink($tmp_zip);
This following code creates me blank zip files.
This is my ip localhostfilemanager/zip_folder.php?directtozip=Screenshots
Directory tree
Screenshots
- Image.jpg
Uploads
^Screenshots
- Image.jpg
And it basically doesn't get any of those files. Why is that? I search recently nearly all codes in google and the codes which worked wasn't based with header output just creating the zip in a directory ./ . Could you provide me with a working code im hopeless :(