Skip to content

Instantly share code, notes, and snippets.

@luizmarcus
Created October 27, 2021 11:15
Show Gist options
  • Save luizmarcus/635c905af74bc974ddf5f69820c71779 to your computer and use it in GitHub Desktop.
Save luizmarcus/635c905af74bc974ddf5f69820c71779 to your computer and use it in GitHub Desktop.
<?php
//identificador unico para o arquivo
define('TOKEN',md5(uniqid(rand(), true)));
function zipFiles(){
$zip = new ZipArchive();
$DelFilePath=$_SERVER['DOCUMENT_ROOT']."/seubot/files/".TOKEN.".zip";
if(file_exists($DelFilePath)) {
unlink($DelFilePath);
}
if ($zip->open($DelFilePath, ZIPARCHIVE::CREATE) != TRUE) {
die("Could not open archive");
}
$path=$_SERVER['DOCUMENT_ROOT']."/seubot/files";
$files = scandir($path);
$files = array_diff(scandir($path), array('.', '..'));
foreach($files as $file){
$zip->addFile($_SERVER['DOCUMENT_ROOT']."/seubot/files/".$file,$file);
}
// close and save archive
$zip->close();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment