【问题标题】:PHP images returning 500 internal server error?PHP图像返回500内部服务器错误?
【发布时间】:2011-01-28 07:24:20
【问题描述】:

我有一些代码可以向图像添加一些标题:

title-background.png.php 的内容:

<?php
$im = imagecreatefrompng("title-background.png");

header('Cache-Control: public');
header('Content-type: image/png');
header('Expires: 19 Febuary 2012 20:00:00 GMT');

imagepng($im);
imagedestroy($im);
?>

而且效果很好。但是当我尝试对另一个文件做同样的事情时,

button.png.php 的内容:

<?php
$im1 = imagecreatefrompng("button.png");

header('Cache-Control: public');
header('Content-type: image/png');
header('Expires: 19 Febuary 2012 20:00:00 GMT');

imagepng($im1);
imagedestroy($im1);
?>

服务器返回 500。 我无权访问我的日志。

【问题讨论】:

  • 你检查图像的路径了吗?您有权访问该文件吗?
  • 尝试将这些行添加到文件的开头以防止 500 错误,然后查看是否收到 php 错误:&lt;?php error_reporting(E_ALL); ini_set('display_errors', 'on'); echo "aaa"; ob_flush(); ?&gt;

标签: php image http-headers


【解决方案1】:

我怀疑button.png 不存在、无法读取或与imagecreatefrompng() 不兼容。

【讨论】:

  • 您认为格式不正确或文件不存在会导致500吗?
  • @zerkms:如果服务器用于处理 PHP 的 SAPI 或使用的自定义框架配置为在 E_ERROR 上返回 500 状态代码,则可以。
【解决方案2】:

哇,对不起,弄乱了 stackoverflow 服务器。在我早餐后 1 分钟内,我解决了...

title-background.png.php 是从同一服务器上的 .css 文件指向的:- 但是,button.png.php 来自不同的服务器!

我现在已经通过放置完整路径来修复它,包括 http://'s 等。

【讨论】:

    猜你喜欢
    • 2011-03-07
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 2013-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    相关资源
    最近更新 更多