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 32 33 34 35 36 37 38 39 40 41
| createZip('C:/Users/bob.b/Documents/GED/word/DIPDE/word/wordbase/','C:/Users/bob.b/Documents/GED/word/DIPDE/word/wordbase/'.date("j-m-Y_G-i").'/');
$zip = new ZipArchive();
if(is_dir('C:/Users/bob.b/Documents/GED/word/DIPDE/word/wordbase/'))
{
if($zip->open('Archive.zip', ZipArchive::CREATE) == TRUE)
{
$fichiers = scandir('C:/Users/bob.b/Documents/GED/word/DIPDE/word/wordbase/');
unset($fichiers[0], $fichiers[1]);
foreach($fichiers as $f)
{
if(!$zip->addFile('C:/Users/bob.b/Documents/GED/word/DIPDE/word/wordbase/'.$f, $f))
{
echo 'Impossible d'ajouter "'.$f.'".<br/>';
}
}
$zip->close();
// On peut ensuite, comme dans le tuto de DHKold, proposer le téléchargement.
header('Content-Transfer-Encoding: binary'); //Transfert en binaire (fichier).
header('Content-Disposition: attachment; filename="Archive.zip"'); //Nom du fichier.
header('Content-Length: '.filesize('Archive.zip')); //Taille du fichier.
readfile('Archive.zip');
}
else
{
echo 'Erreur, impossible de créer l'archive.';
}
}
else
{
echo 'Le dossier "upload/" n'existe pas.';
}
?> |