Search code examples
phpzip

Failure to create ZIP archive, but no error messages


I'm trying to create a ZIP archive of some image files. This directory of files, I have added to an array named $valid. Each item in this array is a string like so:

"uploads/1845_45678_862_speaker.jpg"

This is my code that I'm trying to work, to create a ZIP archive of all of these physical files:

$zip = new ZipArchive();
$zip_name = "ptx_speakers.zip";

$zip->open($zip_name, ZipArchive::CREATE);

foreach ($valid as $zip_item) {
    $zip->addFile($zip_item);
}

$zip->close();

However, this isn't working. Even with error reporting turned on, I just get a blank screen. I tried the following code afterwards, but nothing displayed here either:

if (!file_exists($zip_name)) {
    "No file."
}

Can anyone see a fatal flaw in my code? I can paste more (like how I create the initial array) if you so wish.


Solution

  • Believe it or not, my problem lied not in my script, but in my file/folder permissions. Since I had permission to upload the files in the first place, I assumed I would be able to write with this file, but no, I had to update it's permissions to 757 and then the script worked a charm first time.