Created
January 14, 2015 15:32
-
-
Save xabikip/5a85d9350dc86d7c9dde to your computer and use it in GitHub Desktop.
cron in php to delete files recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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