I am getting a small problem with Zip files. I am using a PHP class to make a zip file and everything works fine but when the zip file is made it contains folders with the file that I ma trying to zip. I want the structure to be clean.
For example if file path is abc/xyz/abc.jpg it should just zip abc.jpg but it contains the whole path in the zip file.
I tested my code locally but didn’t get this problem but when I upload the same code on the server it gives me the whole path.
$fileDir = ‘abc/xyz/’;
include_once(“Zip.php”);
$fileTime = date(“D, d M Y H:i:s T”);
$zip = new Zip();
$file = array(‘131.mp3’,‘music/131.mp3’);
$pathData =$fileDir . $file ;
foreach ($file as $f){
$fn=$f;
$zip->addFile(file_get_contents($fileDir . $fn), $fn, filectime($fileDir . $fn));
}
$zip->finalize(); // as we are not using getZipData or getZipFile, we need to call finalize ourselves.
$zip->setZipFile(“ZipExample2.zip”);
*
Anyone else had this issue. Any help would be appreciated.
Thanks