Just simulate everything, don't actually delete */ if(php_sapi_name() !== 'cli') exit('This script can only be called via CLI'); error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); define('DS', DIRECTORY_SEPARATOR); define('ROOT', dirname(__FILE__).DS.'..'); include_once(ROOT.DS.'inc/config.inc.php'); include_once(ROOT.DS.'inc/core.php'); $pm = new PictshareModel(); if(in_array('sim',$argv)) { echo "[!!!!] SIMULATION MODE. Nothing will be deleted [!!!!] \n\n"; $sim = true; } else $sim = false; $dir = ROOT.DS.'upload'.DS; $dh = opendir($dir); $localfiles = array(); if(in_array('noskip',$argv)) { echo "Won't skip existing files\n\n"; $allowskipping = false; } else $allowskipping = true; //making sure ffmpeg is executable system("chmod +x ".ROOT.DS.'bin'.DS.'ffmpeg'); echo "[i] Finding local mp4 files .."; while (false !== ($filename = readdir($dh))) { $img = $dir.$filename.DS.$filename; if(!file_exists($img)) continue; $type = pathinfo($img, PATHINFO_EXTENSION); $type = $pm->isTypeAllowed($type); if($type) $localfiles[] = $filename; } if(count($localfiles)==0) exit('No files found'."\n"); echo " done. Got ".count($localfiles)." folders\n"; echo "[i] Looking for files to clean up\n"; foreach($localfiles as $hash) { $dir = ROOT.DS.'upload'.DS.$hash.DS; $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { if(!is_file($dir.$filename) || $filename==$hash || $filename == 'last_rendered.txt') continue; echo "[$hash] $filename"; if(!$sim) unlink($dir.$filename); echo "\t".(file_exists($dir.$filename)?'NOT DELETED':'DELETED')."\n"; } }