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 30 31
| function zipDir($path, $zip)
{
if (!is_dir($path)) return;
if (!($dh = @opendir($path)))
{
echo("<b>ERREUR: Une erreur s'est produite sur ".$path."</b><br/>");
return;
}
while ($file = readdir($dh))
{
if($file == "." || $file == "..") continue;
if(is_dir($path."/".$file))
{
zipDir($path."/".$file,$zip);
}
elseif(is_file($path."/".$file))
{
$zip->addFile(file_get_contents($path."/".$file),$file);
echo('fichier '.$path.'/'.$file.' ajouté<br>');
}
}
}
$fichier_zip = '0.zip';
$zip = new zipfile;
$path = 'images';
zipDir($path, $zip);
$filezipped = $zip -> file();
$open = fopen($fichier_zip, "w");
fwrite($open, $filezipped);
fclose($open); |
Partager