我一直在开发一个加载PNG文件的图像处理函数。虽然它在我的本地服务器(Windows,PHP 5.3.6)和远程服务器(FreeBSD,PHP 5.3.6.)上运行良好,但当使用imagecreatefrompng时,PHP返回"500内部服务器错误"。通常,我会查阅/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文件??