Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Didplay every image in a directory
Old 06-19-2009, 11:31 AM Didplay every image in a directory
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
Hi,

I want to display every image that is in a directory. So far I have

PHP Code:
<?php

// Define the full path to your folder, shouldn't need changing
$path "gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open folder");

// Loop through the files
while (false !== ($file readdir($dir_handle))) {

// Prevent this file itself being shown
// If you want it to not display any other files
// enter more of these
if($file == "index.php")
continue;
//Prevent folders showing
if($file == ".")
continue;
if(
$file == "..")
continue;

// Display the results
echo "<img src='$file' alt='$file'><br />";

}

// Close it
closedir($dir_handle);

?>
but this only shows the file name, not the image.

Does anybody know how to swith this so it would show the image. Thanks

Alex
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-19-2009, 02:43 PM Re: Didplay every image in a directory
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
readdir returns a filename, what you need is the path to that file:

PHP Code:
<?php

// Define the full path to your folder, shouldn't need changing
$path "gallery/";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open folder");

// Loop through the files
while (false !== ($file readdir($dir_handle))) {

// Prevent this file itself being shown
// If you want it to not display any other files
// enter more of these
if($file == "index.php")
continue;
//Prevent folders showing
if($file == ".")
continue;
if(
$file == "..")
continue;

// Display the results
$filepath $path $file;
echo 
"<img src='$filepath' alt='$file' /><br />";

}

// Close it
closedir($dir_handle);

?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-19-2009, 04:34 PM Re: Didplay every image in a directory
konetch's Avatar
Ultra Talker

Posts: 258
Trades: 0
okay thanks it worked fine
__________________
Alex
konetch is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Didplay every image in a directory
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.49303 seconds with 12 queries