I have the following file structure. Some files are dynamically added to a zip file and downloaded.
uploads
----- 1
---------- test.jpg
---------- another-test.jpg
----- 2
---------- yetanotherfile.jpg
----- 3
---------- evenmorefiles.jpg
However, when I unzip the downloaded file it keeps that same structure (only with some files missing) and the unzipped folder is called upload.
How can I:
- Change the name of the unzipped folder
- Get rid of the structure
My code for generating the file is
if ($_GET['download']== 'true'){
$downloadarray = array();
while($row = mysql_fetch_array($res)){
$downloadarray[] = $row['loc'] ;
}
$zipname = rand(0,9999) . 'download.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($downloadarray as $file) {
$zip->addFile($file);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename=' . $zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
unlink($zipname);
}
Thanks for any help!