我想用php腳本顯示圖像。這是我目前的代碼:如何返回圖像
<?php
if (isset ($_GET['id'])) $id = $_GET['id'];
$t=getimagesize ($id) or die('Unknown type of image');
switch ($t[2])
{
case 1:
$type='GIF';
$img=imagecreatefromgif($path);
break;
case 2:
$type='JPEG';
$img=imagecreatefromjpeg($path);
break;
case 3:
$type='PNG';
$img=imagecreatefrompng($path);
break;
}
header("Content-type: image/".$type);
echo $img;
?>
但它不顯示圖像。什麼是正確的方式,而不是echo $img
?
' 警告:imagejpeg():提供的參數不是有效的圖像資源'到你的代碼的第二行 – Ockonal 2011-05-19 12:16:22
該問題詢問**返回**圖像...恕我直言,這傢伙的答案是去:[鏈接](https://stackoverflow.com/questions/22266402/how-to-encode-an-image-resource-to-base64)...結合這另一個[鏈接](https:// stackoverflow.com/questions/8499633/how-to-display-base64-images-in-html)必須完成這項工作。 – Nowdeen 2017-07-25 13:16:39