1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
require('include/lib_zip.php');
$fichier_zip ="zip.zip"; // nom du fichier zip que l'on veut
$zip = new zipfile();
$path = "photos"; // repertoire que l'on veut zipper
function zipDir($path,&$zip){
if(!is_dir($path))return;
if(!($dh=@opendir($path))){
return;
}
while($file=readdir($dh)){
if($file=="."||$file=="..")continue; // Throw the . and .. folders
if(is_dir($path."/".$file)){ // Recursive call
zipDir($path."/".$file,$zip,$i);
}elseif(is_file($path."/".$file)){ // If this is a file then add to the zip file
$zip->addFile(file_get_contents($path."/".$file),$path."/".$file);
}
}
}
zipDir($path,$zip);
$filezipped = $zip->file(); // On recupere le contenu du zip dans la variable $filezipped
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="telechargement.zip"');
echo $filezipped; |
Partager