繁体   English   中英

PHP GD无声地失败

[英]PHP GD fails silently

我一直在研究加载PNG文件的图像处理功能。 虽然它在远程服务器上的本地服务器(Windows,PHP 5.3.6)上运行正常(FreeBSD,PHP 5.3.6),但在使用imagecreatefrompng时,PHP会返回“500 Internal Server Error”。 通常,我会查阅/var/log/php.log中的日志 - 但是当我尝试加载页面时,没有任何内容添加到日志中。 如果我注释掉包含imagecreatefrompng的行,脚本会加载 - 尽管由于缺少图像资源而导致很多错误输出到日志中。

我试过添加:

ini_set('display_errors', 1);
error_reporting(E_ALL);

到代码,没有区别。

phpinfo的输出显示GD已加载,gd_info的输出为:

array(12) {
  ["GD Version"]=>
  string(27) "bundled (2.0.34 compatible)"
  ["FreeType Support"]=>
  bool(true)
  ["FreeType Linkage"]=>
  string(13) "with freetype"
  ["T1Lib Support"]=>
  bool(true)
  ["GIF Read Support"]=>
  bool(true)
  ["GIF Create Support"]=>
  bool(true)
  ["JPEG Support"]=>
  bool(true)
  ["PNG Support"]=>
  bool(true)
  ["WBMP Support"]=>
  bool(true)
  ["XPM Support"]=>
  bool(true)
  ["XBM Support"]=>
  bool(true)
  ["JIS-mapped Japanese Font Support"]=>
  bool(false)
}

此时,我完全迷失了。 没有我的PHP安装和再次尝试,我不知道该怎么做。 我计划在端口更新后升级到5.4,但考虑到我不知道问题是什么 - 我不知道这是否会解决问题。

以下是相关代码的片段:

/* load image */
$imgname = '/images/'.$doctype.'_'.side($_GET['side']).".png";
$image_path = trim(shell_exec('pwd')).$imgname;

if(!file_exists($image_path)){
  trigger_error('Image file not found!');
  exit;
}
$im = imagecreatefrompng($image_path);

我已经确定我正在使用图像的绝对路径,双重检查图像存在(file_exists())并且如果不存在则错误输出。 无论我做什么,只要imagecreatefrompng被取消注释,我就会收到一个无声的500错误。

编辑:我添加了代码段:

var_dump(is_readable($image_path));
var_dump(file_exists($image_path));

我的代码导致:

bool(true) bool(true)

因此看起来PHP的图像文件是可读的。 我还验证了该图像是一个实际的PNG文件。 还有其他想法吗?

你检查过文件权限了吗?

if(!file_exists($path) || !is_readable($path))....

有时它让我。

而且,我不是那样但是......如果它真的是一个png文件,你在那之前检查一下吗?

暂无
暂无

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

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