[英]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.