Delete directory before moving
This commit is contained in:
parent
bb248de083
commit
f6f2b59311
2 changed files with 30 additions and 1 deletions
24
includes/functions/deleteDirectory.php
Normal file
24
includes/functions/deleteDirectory.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a directory with all of its contents.
|
||||||
|
*
|
||||||
|
* @author Jay Trees <github.jay@grandel.anonaddy.me>
|
||||||
|
*/
|
||||||
|
|
||||||
|
function delete_directory(string $directoryToDelete)
|
||||||
|
{
|
||||||
|
foreach (scandir($directoryToDelete) as $filename) {
|
||||||
|
$filepath = $directoryToDelete . '/' . $filename;
|
||||||
|
|
||||||
|
if (is_file($filepath)) {
|
||||||
|
unlink($filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_dir($filepath)) {
|
||||||
|
delete_directory($filepath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unlink($directoryToDelete);
|
||||||
|
}
|
|
@ -110,8 +110,13 @@ if ($zip->open($zip_filename)) {
|
||||||
|
|
||||||
if (is_file($filepath)) {
|
if (is_file($filepath)) {
|
||||||
echo 'Rename ' . $filepath . ' to ' . __DIR__ . '/' . $filename . '<br>';
|
echo 'Rename ' . $filepath . ' to ' . __DIR__ . '/' . $filename . '<br>';
|
||||||
rename($filepath, __DIR__ . '/' . $filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_dir($filepath)) {
|
||||||
|
delete_directory($filepath);
|
||||||
|
}
|
||||||
|
|
||||||
|
rename($filepath, __DIR__ . '/' . $filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue