PHP GD无声地失败
发布时间:2020-12-13 22:34:01 所属栏目:PHP教程 来源:网络整理
导读:我一直在研究加载PNG文件的图像处理功能.虽然它在远程服务器上的本地服务器( Windows,PHP 5.3.6)上运行正常(FreeBSD,PHP 5.3.6),但在使用imagecreatefrompng时,PHP会返回“500 Internal Server Error”.通常,我会查阅/var/log/php.log中的日志 – 但是当我尝
我一直在研究加载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文件,你在那之前检查一下吗? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |