Php zipfile creation issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FLMike
Forum Newbie
Posts: 1
Joined: Wed Jul 16, 2008 5:50 pm

Php zipfile creation issue

Post by FLMike »

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.

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;
}   
 
 
Thanks in advance,
FLMike in Beautiful Sunny S.FLA
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: Php zipfile creation issue

Post by WebbieDave »

Is the function dirList returning absolute file paths?
Post Reply