1
當我試圖在我的網站上水印全尺寸圖像時,Im正面臨着一個非常惱人的問題。它突然開始顯示這個錯誤:圖像「bla bla」無法顯示,因爲它包含錯誤PHP幫助:(圖片「bla bla」無法顯示,因爲它包含錯誤
我檢查了一切,似乎一切都工作得很好!我卡住了,我不知道該怎麼辦
這裏是我的水印php文件:
require_once "maincore.php"; if (isset($_GET['photo_id']) && isnum($_GET['photo_id'])) { $result = dbquery("SELECT td.*, tc.* FROM ".DB_PRODUCTS." td LEFT JOIN ".DB_PRODUCT_CATS." tc ON td.product_cat=tc.cat_id WHERE product_id='".$_GET['photo_id']."'"); $data = dbarray($result); define("PHOTODIR", BASEDIR."downloads/images/"); $parts = explode(".", $data['product_image']); $wm_file1 = $parts[0]."_w1.".$parts[1]; $wm_file2 = $parts[0]."_w2.".$parts[1]; if (!isset($_GET['full'])) { $wm_file = PHOTODIR.$wm_file1; } else { $wm_file = PHOTODIR.$wm_file2; } header("Content-type: image/jpg"); $img = PHOTODIR.$data['product_image']; $cop = BASEDIR.$settings['photo_watermark_image']; if (preg_match("/.jpg/i", strtolower($img)) || preg_match("/.jpeg/i", strtolower($img))) { $image = imagecreatefromjpeg($img); } else if (preg_match("/.png/i", strtolower($img))) { $image = imagecreatefrompng($img); } else if (preg_match("/.gif/i", strtolower($img))) { $image = imagecreatefromgif($img); $sizeX = imagesx($image); $sizeY = imagesy($image); $image_tmp = imagecreatetruecolor($sizeX, $sizeY); $ica = imagecolorallocate($image_tmp, 255, 255, 255); imagefill($image_tmp, 0, 0, $ica); if ($settings['thumb_compression'] == "gd2") { imagecopyresampled($image_tmp, $image, 0, 0, 0, 0, $sizeX, $sizeY, $sizeX, $sizeY); } else { imagecopyresized($image_tmp, $image, 0, 0, 0, 0, $sizeX, $sizeY, $sizeX, $sizeY); } $tmp = PHOTODIR.md5(time().$img).'.tmp'; imagejpeg($image_tmp, $tmp); imagedestroy($image_tmp); $image = imagecreatefromjpeg($tmp); unlink($tmp); } if (file_exists($cop) && preg_match("/.png/i", strtolower($cop)) && $settings['photo_watermark']) { $image2 = false; $image_dim_x = imagesx($image); $image_dim_y = imagesy($image); $copyright = imagecreatefrompng($cop); $copyright_dim_x = imagesx($copyright); $copyright_dim_y = imagesy($copyright); $where_x = $image_dim_x - $copyright_dim_x - 5; $where_y = $image_dim_y - $copyright_dim_y - 5; imagecopy ($image, $copyright, $where_x, $where_y, 0, 0, $copyright_dim_x, $copyright_dim_y); $thumb_w = 0; $thumb_h = 0; if (!isset($_GET['full'])) { if ($image_dim_x > $settings['photo_w'] || $image_dim_y > $settings['photo_h']) { if ($image_dim_x $image_dim_y) { $thumb_w = $settings['photo_w']; $thumb_h = round(($image_dim_y * $settings['photo_w'])/$image_dim_x); } else { $thumb_w = $settings['photo_w']; $thumb_h = $settings['photo_h']; } } else { $thumb_w = $image_dim_x; $thumb_h = $image_dim_y; } $image2 = imagecreatetruecolor($thumb_w, $thumb_h); if ($settings['thumb_compression'] == "gd2") { imagecopyresampled($image2, $image, 0, 0, 0, 0, $thumb_w, $thumb_h, $image_dim_x, $image_dim_y); } else { imagecopyresized($image2, $image, 0, 0, 0, 0, $thumb_w, $thumb_h, $image_dim_x, $image_dim_y); } imagedestroy($image); } } //create image if ($settings['photo_watermark_save']) { imagejpeg(($image2 ? $image2 : $image), $wm_file); } imagejpeg((isset($image2) && $image2 ? $image2 : $image)); imagedestroy((isset($image2) && $image2 ? $image2 : $image)); if (isset($copyright) && is_resource($copyright)) { ImageDestroy($copyright); } } else { redirect("index.php"); }
請幫幫我!謝謝!
天啊!我的包含文件在?>之後有3個空格,當我刪除它時,它就起作用了!這樣一個愚蠢的錯誤!謝謝你,伊恩!我感謝您的幫助! – 2012-03-12 18:43:45
@HessanAdnani - 這就是爲什麼[PHP正確的方式](http://www.phptherightway.com/)和標準像[PSR-2](http://www.php-fig.org/psr/psr- 2)表示不要在任何PHP文件中放入'?>'! – ash 2015-12-21 13:49:27