Jump to content

[SOLVED] trying to get all files from directory


AviNahum

Recommended Posts

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!

 

hiynh2jzjrm5.jpg

 

***Sorry for very poor english***

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'.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.