Jump to content

Further PHP-ZIP Help


herghost

Recommended Posts

Hi all

 

My script now works, and the files are added to the zip, however the 1st two directories in my zip are 'uploads' and then the username, basically I want the zipped files to start from within the users directory and I just cant figure out what I need to do, any help would be greatly appreciated, been looking at these 30 odd lines for 6 hours :P

 

//make zip


$sourcefolder = "uploads/".$username.""; 
$zipfilename  = "uploads/".$username.".zip"; 
$timeout      = 5000; 

$dirlist = new RecursiveDirectoryIterator($sourcefolder);
$filelist = new RecursiveIteratorIterator($dirlist);

ini_set('max_execution_time', $timeout);

$zip = new ZipArchive();

if ($zip->open("$zipfilename", ZipArchive::CREATE) !== TRUE) {
    die ("Could not open archive");
}

foreach ($filelist as $key=>$value) {
    $zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
}

$zip->close();
echo "<br>Archive ". $zipfilename . " created successfully.";

?>
<br /><a href="http:<?php echo $zipfilename;?>" target="_blank">
Download <?php echo $zipfilename?></a>

Link to comment
https://forums.phpfreaks.com/topic/254584-further-php-zip-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.