1
I can’t identify where I’m going wrong..
The Code below is deleting my uploads folder and is where the files are coming from, but actually I would like you to delete the uploads/folder files and not the uploads folder. Any possible help?
EDIT: It is not deleting the entire folder, but rather the files in the subfolders: "uploads/subfolder/file.extensao <- is the.extensao file that should be deleted only.
Thanks in advance!
<?php
$src = 'uploads';
$dst = 'bkp/';
rcopy($src, $dst); // Call function
// 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 );
rrmdir ( $src );
}
// 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);
}
?>
Possible duplicate of How to delete files inside a folder
– Wees Smith
In my case, I’m only wanting to delete the files from the uploads subfolders. Not the whole folder, as quoted.But from the above code.
– JeanTdz