I'm using php to create a ziparchive which contains some images. This works fine exept when i try to rename the files. This is the code that works:
$zip_archive->open(tempnam("tmp", "zip"), ZipArchive::OVERWRITE);
foreach ($images as $image) {
$path = $image['path'];
$title = $image['title'];
if(file_exists($path)){
$zip_file->addFile($path, pathinfo($path, PATHINFO_BASENAME));
}
}
$zip_archive->close();
$images is an array and could look like this:
$images = array(
'path' => array(
'folder/title1.jpg',
'folder/title2.jpg'
),
'title' => array(
'new_name1.jpg',
'new_name2.jpg'
)
)
I would like to name the image as its title.
$zip_file->addFile($path, $title);
But whats happening is that the files in the zip with the title as name are empty. What am I doing wrong?