note 128044 added to ziparchive.addemptydir
| From: | iunknownvb at gmail dot com | Date: | Fri, 23 Dec 2022 04:32:41 +0000 |
| Subject: | note 128044 added to ziparchive.addemptydir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220000@lists.php.net to get a copy of this message | ||
I have modified thomas dot rubbert at yahoo dot de a little bit
$uploads_dir =storage_path().'/app/public/files/' ;
if(!file_exists($uploads_dir)){
mkdir($uploads_dir,0777,true);
}
$zip_file=$uploads_dir.'download.zip';
if(file_exists($zip_file)){
unlink($zip_file);
}
$zip = new \ZipArchive();
if (!$zip->open($zip_file, \ZIPARCHIVE::CREATE)) {
http_response_code(501);
echo 'Zip creation failed';
die();
}
$img=$uploads_dir.'img';
$dirName = realpath($img);
if (substr($dirName, -1) != DIRECTORY_SEPARATOR) {
$dirName.= DIRECTORY_SEPARATOR;
}
$dirStack = array($dirName);
//Find the index where the last dir starts
$cutFrom = strrpos(substr($dirName, 0, -1), DIRECTORY_SEPARATOR)+1;
while (!empty($dirStack)) {
$currentDir = array_pop($dirStack);
$filesToAdd = array();
$dir = dir($currentDir);
while (false !== ($node = $dir->read())) {
if (($node == '..') || ($node == '.')) {
continue;
}
if (is_dir($currentDir . $node)) {
array_push($dirStack, $currentDir . $node . DIRECTORY_SEPARATOR);
}
if (is_file($currentDir . $node)) {
$filesToAdd[] = $node;
}
}
$localDir =str_replace(DIRECTORY_SEPARATOR,'/',substr($currentDir, $cutFrom));
$zip->addEmptyDir($localDir);
foreach ($filesToAdd as $file) {
$zip->addFile($currentDir . $file, $localDir . $file);
}
}
// any additional files
$db=$uploads_dir.'databse.db';
//$zip->addFromString(basename($db), file_get_contents($db));
$zip->addFile($db, basename($db));
$zip->close();
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.175 (proxied: 117.216.230.198)
----
Manual Page -- https://php.net/manual/en/ziparchive.addemptydir.php
Edit -- https://main.php.net/note/edit/128044
Del: integrated -- https://main.php.net/note/delete/128044/integrated
Del: useless -- https://main.php.net/note/delete/128044/useless
Del: bad code -- https://main.php.net/note/delete/128044/bad+code
Del: spam -- https://main.php.net/note/delete/128044/spam
Del: non-english -- https://main.php.net/note/delete/128044/non-english
Del: in docs -- https://main.php.net/note/delete/128044/in+docs
Del: other reasons-- https://main.php.net/note/delete/128044
Reject -- https://main.php.net/note/reject/128044
Search -- https://main.php.net/manage/user-notes.php