Ich schreibe ein Skript, das Ordner und Dateien im Inneren archivieren muss, aber ich kann nicht herausfinden, wie es geht, wenn es einen anderen Ordner in einem Ordner gibt. Ich werde mit gutem Beispiel erklären, so die Normen arbeitenzipArchivieren, wie Ordner im Ordner speichern
Warning: ZipArchive::close(): Read error: Is a directory in /путь до скрипта/public_html/crm/drive/drive.php on line 102
Folder +
File1
File2
And so on (so it works)
But does not want to work like that
Folder +
File1
FOLDER (this does not work)
Die Frage ist, wie man es machen, so dass, wenn das Skript der Ordner sieht es auch heruntergeladen und wenn ich den Ordner in diesem Ordner sah, auch heruntergeladene Dateien in den jeweiligen Ordnern? Hier ist mein Skript
if (isset($_POST['createPath'])) {//Check that the button is clicked
$zip = new ZipArchive(); // Create an archive
$zip_name = time().".zip"; // file name
if ($zip->open($zip_name, ZipArchive::CREATE) !== true) { // open file
die ("Could not open archive");//If the file does not open
}
$var = $_POST["pathUpload"];// Array of variables that are passed through the form
foreach ($var as $key_var) {// We process the array in a loop
$iterator = new RecursiveDirectoryIterator($key_var);//There is a recursive search of the file system directories
foreach ($iterator as $key => $value) {// We process an array of files
$path = pathinfo($value);//Check the path or revert the path to the file
if ($path['basename'] == '.' || $path['basename'] == '..') continue;//Check those files that you download if there are points in the files then download
$zip->addFile(realpath($key), $key);//Add the file to the server
}
$zip->close();//Close archive
if (file_exists($zip_name)) {
// Give the file to download
header('Content-type: application/zip', 'charset=utf-8');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
ob_end_flush();//Buffering since without it nothing will work
readfile($zip_name); //Read the file
unlink($zip_name);//Delete the variable
}
}
}
Ich entschuldige mich, aber es ist möglich noch eine frage poche ist es für mich notwendig, den code wie auf strinitsu ordnern einzufügen, und es gibt keine fehler – Vadim