PHP List Images In Folder
I have the following code
// Define the full path to your folder from root
$path = "../galleries/".$album;
// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");
// Loop through the files
while ($file = readdir($dir_handle)) {
if(strlen($file)>1){echo "<a href='http://minification.com/?page_id=32&dir=$album&img=$file'><img src='http://minification.com/galleries/$album/$开发者_Go百科file'></a>";}
}
// Close
closedir($dir_handle);
What i want to do is pull in all the images from a folder and display them using PHP. So far its working up to the point where it only displays one image out of the folder. Anyone know how to fix this?
Your second file probably evaulates to false, see readdir(), you should do:
while (false !== ($file = readdir($dir_handle))) {
Hint: If this is PHP 5, you can reduce the hassle a bit by using scandir
instead.
try this:
while(false !== ($file = readdir($handle))) {
A lot of different values evaluate to false in php so you may be getting a false positive.
精彩评论