繁体   English   中英

使用readfile加载时,为什么我的图像显示不正确

[英]Why is my image not being displayed correct when loading it using readfile

我正在尝试使用其文件路径读取缩略图。

$thumb = "/location/of/image";

$getInfo = getimagesize($thumb);
header('Content-type: ' . $getInfo['mime']);
readfile($thumb);

结果是图像错误图标。

到目前为止我已经尝试过;

  • 检查文件是否存在

var_dump(file_exists($thumb));

结果:

bool(true)
  • 检查getInfo以确保它是一个图像:

    后续代码var_dump($的getInfo);

结果:

array(7) {
  [0]=>
  int(100)
  [1]=>
  int(94)
  [2]=>
  int(2)
  [3]=>
  string(23) "width="100" height="94""
  ["bits"]=>
  int(8)
  ["channels"]=>
  int(3)
  ["mime"]=>
  string(10) "image/jpeg"

}

这似乎是正确的(大小mime类型等)

使用file_get_contents($ thumb)而不是file_read(一个完整的范围,但我已经用完了想法)。

  • 我检查了它正在读取的文件,我可以毫无问题地下载和查看图像,如果我直接从浏览器调用该文件,图像显示正常。 所以它看起来不像那样

  • 强制文件下载而不是显示:

    header(“Content-Type:application / force-download”);

    任何图像编辑器/视图或浏览器都无法识别生成的文件。 即使我将下载文件名明确设置为“thumb.jpg”,也会出现一系列错误,从“不完整”到“无法识别的格式”结果。

我没有想法! 有没有人提出任何其他建议如何调试此问题?

在此先感谢您的建议:)

你可以试试这个:

$thumb = "/location/of/image";

$getInfo = getimagesize($thumb);

header('Content-type: ' . $getInfo['mime']);

ob_clean();

flush();

readfile($thumb);

在打开php标签之前可能还有一些空白区域。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM