Make sure you have unique name directory
$directory = “images/directory”;
empty($directory);
function empty($directory)
{
$dirHandle = opendir($directory);
// Loop over all of the files in the folder
while ($file = readdir($dirHandle)) {
// If $file is NOT a directory remove it
if(!is_dir($file)) {
unlink (“$directory”.”$file”); // unlink() deletes the files
}
}
// Close the directory
closedir($dirHandle);
empty($directory);
function empty($directory)
{
$dirHandle = opendir($directory);
// Loop over all of the files in the folder
while ($file = readdir($dirHandle)) {
// If $file is NOT a directory remove it
if(!is_dir($file)) {
unlink (“$directory”.”$file”); // unlink() deletes the files
}
}
// Close the directory
closedir($dirHandle);
// you can skip this state in case you just want to remove directory only
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
echo “directory empty successfully!”;
}