Fellow coders:
Hate to ask this question, as it was, I belive correctly answered two times:
So the problem is: when unzipping the downloaded 'file.zip', after unzipping, it contains all the folders from the path, even tough I specified the local file in the addFile function. I'd like the zip file not to contain any subfolder, just files.
$zipname = str_replace(' ', '_', $obj['Name']) . '.zip';
$zip = new ZipArchive();
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
// $file looks like this: webroot/uploadify/files/file.jpg
$zip->addFile($file, pathinfo($file, PATHINFO_BASENAME));
}
$zip->close();
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=" . $zipname);
header("Pragma: no-cache");
header("Expires: 0");
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
Can anyone see what's the problem with this code?
Additional info:
I, ofc, use paths relative to the webroot, but the folder hierarchy in the extracted folder after: extract to file -> 'my_file.zip' is C->xampp->htdocs->my_cakephp_web_app->app->webroot->files which is not exactly what I wanted to achieve :)
PHP 5.4.4
Windows XP, XAMPP
EDIT
Tried using the http://www.phpconcept.net/pclzip/ library and had the same problem. Also on my home PC ( win7 ) this code worked well.
This brings up a question: Are there any settings I should meet that I'm not aware of?