I've created the following code to create a zip file. I'm pulling a list of files from the database depending on the $job_number (which I'm getting from the global $_GET array) and then trying to add them to the zip file.
That part is working fine. It's pulling the list of files from the database, as I can see by echoing or dumping with print_r
the results.
The only problem is that the .zip file isn't being created at all. I can't see where I've gone wrong.
$sth = $conn->prepare('SELECT `dp_filename` FROM damage_pics WHERE dp_job_number = :job_number');
$sth->bindParam(':job_number', $job_number);
$sth->setFetchMode(PDO::FETCH_ASSOC);
$sth->execute();
$zip = new ZipArchive();
$zip->open('example5.zip', ZipArchive::CREATE);
$result = $sth->fetchAll();
echo '<pre>';
print_r($result);
foreach ($result as $file)
{
// just echoing for testing purposes to see if file name is created correctly.
$image = $file['dp_filename'];
echo $image . "<br />";
$zip->addFile("uploads/{$image}");
}
$zip->close();