0

我试图在屏幕上的“上传”文件夹中显示图像,但我不断收到损坏的图像图标。我知道它正在正确读取目录,因为我可以右键单击并在新选项卡中打开图像并显示它。

<?php
$dir = "uploads/";

// Open a directory, and read its contents
if ($opendir = opendir($dir)) {
     while (($file = readdir($opendir)) !== FALSE) {
          if ($file != "." && $file != "..") {
               echo "<img src='$dir/$files'><br>";
          }
     }
}
?>
4

1 回答 1

0

您的 $files 变量中几乎没有机械错误)像“$file”一样使用它,而不是“$files”:)

复制此代码,它将起作用。

<?php
    $dir = "uploads/";

    // Open a directory, and read its contents
    if ($opendir = opendir($dir)) {
         while (($file = readdir($opendir)) !== FALSE) {
              if ($file != "." && $file != "..") {
                   echo "<img src='$dir/$file'><br>";
              }
         }
    }
    ?>

于 2017-01-11T05:57:24.503 回答