Lamez Posted August 21, 2008 Share Posted August 21, 2008 I have a folder filled with a bunch of images, that are named 1.jpeg, 2.jpeg 3.jpeg but there is about 30-40, so is there a way to delete all the images in the folder? Quote Link to comment https://forums.phpfreaks.com/topic/120658-solved-delete-multiple-files-in-a-folder/ Share on other sites More sharing options...
The Little Guy Posted August 21, 2008 Share Posted August 21, 2008 Careful how this is used, the following will delete everything in the folder with a file extension of jpg (* stand for wild card) foreach(glob('/my/folder/*.jpg') as $file){ unlink($file); } Quote Link to comment https://forums.phpfreaks.com/topic/120658-solved-delete-multiple-files-in-a-folder/#findComment-621748 Share on other sites More sharing options...
Lamez Posted August 21, 2008 Author Share Posted August 21, 2008 could I do foreach(glob('/my/folder/*.jpg && *.jpeg') as $file){ unlink($file); } Quote Link to comment https://forums.phpfreaks.com/topic/120658-solved-delete-multiple-files-in-a-folder/#findComment-621752 Share on other sites More sharing options...
mmarif4u Posted August 21, 2008 Share Posted August 21, 2008 Did you tried that for jpg,i think it should also work for jpeg. NOT SURE. It will delete both types, by just using jpg.i think so Quote Link to comment https://forums.phpfreaks.com/topic/120658-solved-delete-multiple-files-in-a-folder/#findComment-621755 Share on other sites More sharing options...
Lamez Posted August 21, 2008 Author Share Posted August 21, 2008 well I did not try, but it would not hurt to add 2 foreach loops <?php foreach(glob($idir.'*.jpg') as $file){ unlink($file); } foreach(glob($idir.'*.jpeg') as $file){ unlink($file); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/120658-solved-delete-multiple-files-in-a-folder/#findComment-621762 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.