Created
June 27, 2019 22:02
-
-
Save somoza/520c9a4cce1451efb04a137c27b96b3d to your computer and use it in GitHub Desktop.
Move entire folder and their content with PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function to remove folders and files | |
function rrmdir($dir) { | |
if (is_dir($dir)) { | |
$files = scandir($dir); | |
foreach ($files as $file) | |
if ($file != "." && $file != "..") rrmdir("$dir/$file"); | |
rmdir($dir); | |
} | |
else if (file_exists($dir)) unlink($dir); | |
} | |
// Function to Copy folders and files | |
function rcopy($src, $dst) { | |
if (file_exists ( $dst )) | |
rrmdir ( $dst ); | |
if (is_dir ( $src )) { | |
mkdir ( $dst ); | |
$files = scandir ( $src ); | |
foreach ( $files as $file ) | |
if ($file != "." && $file != "..") | |
rcopy ( "$src/$file", "$dst/$file" ); | |
} else if (file_exists ( $src )) | |
copy ( $src, $dst ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment