I have built an application which uploads HTML canvas elements to a directory on the server, and then zips and downloads that directory.
The first part of this (uploading the canvas elements) is working perfectly. All of the .png files are uploaded 100% of the time. However, whenever I come to zip and download the directory contents, it seems that files are being missed/skipped.
Here is the code I'm using to zip the directory:
if($x == $l) { // $x = number of .PNGs, $l = expected number
$zip = new ZipArchive();
$zipPath = "../titles/" . $folder . ".zip";
if ($zip->open($zipPath, ZIPARCHIVE::CREATE )!==TRUE) {
exit("cannot open" . $zipPath> . "
");
}
$list = scandir($path);
foreach($list as $value) {
$ex = explode(".", $value);
if($ex[1]=="png") {
$zip->addFile($path.$value, $value);
}
}
$zip->close();
echo "titles/" . $folder . ".zip"; // Sends path back to browser for download
}
There is no consistent pattern with files being missed out of the zip folder. Occasionally they will all be there, but more often than not some will be missing.
Does anyone know what might be causing this/how it could be fixed? Thanks!