mcmuney Posted September 27, 2007 Share Posted September 27, 2007 I'm trying to modify this script to remove files that end with %enlarged.jpg or %enlarged.gif or %enlarged.png, can someone help with the if statement, I've tried several things, of which, nothing is working: <? $path = 'mem_images/xyz/'; // path to the directory to read if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if(strrchr($file, '.') == '.png' || strrchr($file, '.') == '.gif' || strrchr($file, '.') == '.jpg') { if(!is_dir($file)){ if($file){ echo $file." <<< No Match Found - File Deleted<br>" ; //Uncomment the line below once you have made sure the Query works and presents you a list of images not found. Just a precaution till you are sure its correct. unlink("$path".$file) ; //unlink("$file") ; } } } } } closedir($handle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/70829-deleting-files/ Share on other sites More sharing options...
teng84 Posted September 27, 2007 Share Posted September 27, 2007 try foreach (glob("*enlarged.txt") as $filename) { unlink($filename); echo "$filename size " . filesize($filename) . "has been deleted\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/70829-deleting-files/#findComment-356096 Share on other sites More sharing options...
mcmuney Posted September 27, 2007 Author Share Posted September 27, 2007 Nope, that didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/70829-deleting-files/#findComment-356619 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.