【问题标题】:Image output not working php图像输出不起作用php
【发布时间】:2016-05-10 16:27:59
【问题描述】:

我正在使用的课程中有一个奇怪的行为。 该类调整图像大小并输出它。相关代码如下:

// output the image
header("Content-Disposition: filename={$output};");
header("Content-Type: {$info["mime"]}");
header('Content-Transfer-Encoding: binary');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');

readfile($output);

结果就是这个奇异的小方块:

HTML 如下:

 <img style="-webkit-user-select: none" src="http://localhost/tv-tracker/images/media/2/backdrop-100x100.jpg">

任何帮助将不胜感激!

【问题讨论】:

  • header("Content-Type: {$info["mime"]}"); 的问题
  • 我怀疑错误报告和来自服务器的响应表明存在语法错误。不要只看网页上的“图片”,要看实际的服务器响应。

标签: php


【解决方案1】:

滥用",嵌套使用会出现问题,只需更改给定标题的内容类型即可。

header("Content-Type: {$info["mime"]}");

header("Content-Type: {$info['mime']}");

例子:

$output = 'http://placehold.it/350x150';
header("Content-Disposition: filename={$output};");
header("Content-Type: image/jpeg");
header('Content-Transfer-Encoding: binary');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');

readfile($output);

【讨论】:

  • 改变了这个,但它仍然没有工作。我在 readfile() 之前添加了 obclean() 并且它不起作用(正如那里所建议的 stackoverflow.com/a/28479155/2432113
  • 作为我的例子,我得到了这个工作,我发现只有一个错误。您也可以查看我给出的示例,可能是您有一些服务器问题..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-07
  • 2013-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多