Php zipfile creation issue
Posted: Wed Jul 16, 2008 6:04 pm
Hi all, first post...
I have created a zip script that works very well, my only issue is that when the archive is created it doesn't just get created with the files it gets created with the entire dir structure of my application, so for example if the files I want to archive are in this dir structure C:\AppServ\www\application\uploads\files_dir\, that is how my zip archive is created where in I only want the files_dir archived. Is there a way to do this. I will post my zip function as well for you to see.
Thanks in advance,
FLMike in Beautiful Sunny S.FLA
I have created a zip script that works very well, my only issue is that when the archive is created it doesn't just get created with the files it gets created with the entire dir structure of my application, so for example if the files I want to archive are in this dir structure C:\AppServ\www\application\uploads\files_dir\, that is how my zip archive is created where in I only want the files_dir archived. Is there a way to do this. I will post my zip function as well for you to see.
Code: Select all
function createZip($dir,$leadID,$dateAdded){
// create object
$zip = new ZipArchive();
$name = date("Ymd")."_".$leadID."_".uniqid();
// open archive
if ($zip->open($name.'.zip', ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
$fileList = dirList ($dir);
// add files
foreach ($fileList as $f) {
$zip->addFile($f) or die ("ERROR: Could not add file: $f");
}
// close and save archive
$zip->close();
//move and delete files
$src = SITE_ROOT. DIR_SEPARATOR .'scripts'. DIR_SEPARATOR .$name.'.zip';
$dest = SITE_ROOT. DIR_SEPARATOR .'uploads'. DIR_SEPARATOR .'files'. DIR_SEPARATOR .$name.'.zip';
$ret = copy($src,$dest);
if($ret == true){
unlink($src);
} else {
echo 'Copy Failed';
}
delete_directory($dir);
return true;
}
FLMike in Beautiful Sunny S.FLA