Using PHP script to delete a multiple files

This is short php script to delete files file by file in a loop. To do deletion with PHP, use this little PHP script:

$dir = "/directory/";
$dh = opendir($dir);
$i = 0;
while (($file = readdir($dh)) !== false) {
$file = "$dir/$file";
if (is_file( $file)) {
unlink( $file);
if (!(++$i % 100)) {
echo "$i files removedn";

This script helpful in deleting large files in a particular directory.

Leave a Reply

Your email address will not be published.

Enter Captcha Here : *

Reload Image