1

我有以下代码

    // 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/$file'></a>";}

    } 

    // Close 
    closedir($dir_handle); 

我想要做的是从一个文件夹中提取所有图像并使用 PHP 显示它们。到目前为止,它的工作一直到只显示文件夹中的一张图像。有人知道怎么修这个东西吗?

4

3 回答 3

3

您的第二个文件可能评估为假,请参阅readdir(),您应该这样做:

while (false !== ($file = readdir($dir_handle))) {
于 2010-08-11T15:49:01.057 回答
3

提示:如果这是 PHP 5,您可以通过使用来减少麻烦scandir

于 2010-08-11T15:52:48.917 回答
1

尝试这个:

while(false !== ($file = readdir($handle))) {

许多不同的值在 php 中评估为 false,因此您可能会得到误报。

于 2010-08-11T15:49:55.723 回答