Skip to content

Instantly share code, notes, and snippets.

@random-robbie
Created October 1, 2014 10:09
Show Gist options
  • Save random-robbie/7f4d32703f75c3cf65e0 to your computer and use it in GitHub Desktop.
Save random-robbie/7f4d32703f75c3cf65e0 to your computer and use it in GitHub Desktop.
PHP - Remove 0kb files from folder and put text file with removed file's in.
<?php
$fol = "/var/www/zerobytes/test/";
if ($handle = opendir($fol)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && $entry != "removed.txt" && $entry != is_dir("".$fol."".$entry."")) {
//Check filesize
if(filesize("".$fol."".$entry."") < '1000'){
$myfile = fopen("".$fol."removed.txt", "a") or die("Unable to open file!");
$txt = "$entry\r\n";
fwrite($myfile, $txt);
fclose($myfile);
echo "".$entry." - Removed <br>";
unlink ("".$fol."".$entry."");
}
}
}
closedir($handle);
}
echo "If no files are listed above then the files are bigger than 0kb";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment