Answers for "how to delete files from folder in php"

PHP
10

php how to delete file

if(file_exists($file)) {
	unlink($file);
}
Posted by: Guest on January-13-2020
0

php delete a folder

function deleteDirectory($dir) {
    if (!file_exists($dir)) {
        return true;
    }

    if (!is_dir($dir)) {
        return unlink($dir);
    }

    foreach (scandir($dir) as $item) {
        if ($item == '.' || $item == '..') {
            continue;
        }

        if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) {
            return false;
        }

    }

    return rmdir($dir);
}
Posted by: Guest on March-10-2021

Code answers related to "how to delete files from folder in php"

Browse Popular Code Answers by Language