[英]header(Content-type: image/jpeg) not working
我已經編寫了一些代碼來調整圖像大小(遵循PHP手冊)但我無法顯示圖像。 我知道圖像數據存在,因為當我回顯$拇指時我可以看到它,但我似乎無法顯示實際圖像。
這是我用過的代碼:
$row = mysql_fetch_array($result);
$image = $row["image"];
echo $image;
echo $row["name"];
list($width, $height) = getimagesize($image);
$newwidth = $width * 0.1;
$newheight = $height * 0.1;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($image);
imagecopyresized($thumb, $source, 0,0,0,0, $newwidth, $newheight, $width, $height);
header('Content-Length: '.strlen($thumb), true);
header("Content-type: image/jpeg");
echo imagejpeg($thumb);
感謝您的任何幫助
$thumb
刪除\\t
echo $image;
和echo $row["name"];
。 index.php:
$row = mysql_fetch_array($result);
$image = $row["image"];
echo $image;
echo $row["name"];
echo '<img src="image.php">';
image.php:
$row = mysql_fetch_array($result);
$image = $row["image"];
list($width, $height) = getimagesize($image);
$newwidth = $width * 0.1;
$newheight = $height * 0.1;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($image);
imagecopyresized($thumb, $source, 0,0,0,0, $newwidth, $newheight, $width, $height);
$h = str_replace('\t','',$thumb);
header('Content-Length: '.strlen($h), true);
header("Content-type: image/jpeg");
imagejpeg($thumb);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.