images..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

images..

Post by tommy1987 »

Hi, here is my problem,, I have a directory where all uploaded images go, and basically I want a page which just loops over the dir getting all images from it, and just dumping them on the screen is that poss? if so can anyone give any pointers as to how? thanks very much,,
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

This should do it (untested)

Code: Select all

$fs_path = '/absolute/path/to/images';
$web_path='/web/accessible/path/to/images';

chdir($fs_path);
$files = glob('*');

foreach($files as $filename)
{
   echo "<img src = '$web_path/$filename' />";
}
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

Code: Select all

$fs_path = '/absolute/path/to/images'; 
$web_path='/web/accessible/path/to/images'; 

chdir($fs_path); 
$files = glob('*'); 

foreach($files as $filename) 
{ 
   if (!in_array($filename,array('.','..'))) {  // <-- to exclude unwanted items
       echo "<img src = '$web_path/$filename' />"; 
   }
}
Post Reply