【问题标题】:In PHP, images pulled from my directory are broken在 PHP 中,从我的目录中提取的图像已损坏
【发布时间】:2017-05-25 18:51:39
【问题描述】:

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

<?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>";
          }
     }
}
?>

【问题讨论】:

  • 尝试在那里提供完整路径而不是$dir/$files

标签: php image upload brokenimage


【解决方案1】:

您的 $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>";
              }
         }
    }
    ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    • 1970-01-01
    • 2017-12-29
    • 1970-01-01
    • 2017-06-23
    • 2015-11-30
    相关资源
    最近更新 更多