Skip to content

Instantly share code, notes, and snippets.

@xabikip
Created January 14, 2015 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xabikip/5a85d9350dc86d7c9dde to your computer and use it in GitHub Desktop.
Save xabikip/5a85d9350dc86d7c9dde to your computer and use it in GitHub Desktop.
cron in php to delete files recursively
#!/usr/bin/php
<?php
delete_file("/home/piko/curso-php/uploads/astinddu/");
function delete_file($ruta){
if (is_dir($ruta)) {
if ($dir = opendir($ruta)) {
while (($file = readdir($dir)) !== false) {
if(is_dir($ruta . $file) !== true && $file!="." && $file!=".."){
if(filesize("$ruta$file") == 0) unlink("$ruta$file");
}
if (is_dir($ruta . $file) && $file!="." && $file!=".."){
delete_file($ruta . $file . "/");
}
}
closedir($dir);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment