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***

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.