AviNahum Posted June 25, 2009 Share Posted June 25, 2009 i trying to get all files that exist in my "uploads" directory... im using this code: //+--------------------------------------------------- // Getting out all images from the images directory //+--------------------------------------------------- $dir = 'uploads'; $files = scandir($dir); foreach($files as $ind_file){ echo '<img src="'.$dir.'/'.$ind_file.'" width="120">'; } this code works fine... but there is a problem... there are only pictures on this folder, and i insert the file name into "<img>" tag in the foreach loop... its display all the pictuers but its always shows me 2 pics without a URL.... those 2 picstures does not exist in this folder! ***Sorry for very poor english*** Link to comment https://forums.phpfreaks.com/topic/163620-solved-trying-to-get-all-files-from-directory/ Share on other sites More sharing options...
Adam Posted June 25, 2009 Share Posted June 25, 2009 Try this: foreach($files as $ind_file){ if ($ind_file != '.' && $ind_file != '..') { echo '<img src="'.$dir.'/'.$ind_file.'" width="120">'; } } http://us.php.net/manual/en/function.scandir.php If you look at the manual you'll see two directories in there as well: '.' & '..' I bet if you look at the source of your page you'll notice the images where trying to use these as the 'src'. Link to comment https://forums.phpfreaks.com/topic/163620-solved-trying-to-get-all-files-from-directory/#findComment-863313 Share on other sites More sharing options...
dzelenika Posted June 25, 2009 Share Posted June 25, 2009 These are probably directories: . and .. you should exclude them in foreach loop. Link to comment https://forums.phpfreaks.com/topic/163620-solved-trying-to-get-all-files-from-directory/#findComment-863315 Share on other sites More sharing options...
AviNahum Posted June 25, 2009 Author Share Posted June 25, 2009 thanks MrAdam.... its works! and thank you too dzelenika.... Link to comment https://forums.phpfreaks.com/topic/163620-solved-trying-to-get-all-files-from-directory/#findComment-863318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.