Hi!
In a single script, I need to do the following:
- create a zip out of files in a directory
- force the download of the newly create zip
My problem is that whenever I try to do this in a single script, the downloaded zip is corrupted (filesize is ok though). If I trig the processes in two separate script calls, the downloaded zip is ok.
I guess that the problem is that the zip saving to file process isn't completely finished before the download starts. Strangely, it doesn't solve the problem to insert a sleep(3) between the processes... Code outline below.
How to assure that the zip file is completely finished before the force download starts?
Regards / Jonas
// 1. create a zip
$createZipFile = new CreateZipFile('temp.zip');
$createZipFile->zipDirectory('temp/', '.');
$createZipFile->saveZipFile();
sleep(3); // <-- Doesn't matter!
// 2. force zip download
$fileServer = new FileServer();
// Line below gives a corrupted zip when run in same script as 1.
$fileServer->forzeDownload('temp.zip');