此示例代碼片段應該按照您的要求進行操作。如果在服務器上啓用了魔術引號,我還包含了代碼去除斜槓。這將使您的代碼更加便攜,並且與未來版本的PHP兼容。我還添加了使用getimagesize()來檢測MIME類型,以便爲圖像輸出正確的標題,而不必假定它是特定類型的。
<?php
if(isset($_GET['pic']))
{
//Only strip slashes if magic quotes is enabled.
$pic = (get_magic_quotes_gpc()) ? stripslashes($_GET['pic']) : $_GET['pic'];
//Change this to the correct path for your file on the server.
$pic = '/your/path/to/real/image/location/'.$pic;
//This will get info about the image, including the mime type.
//The function is called getimagesize(), which is misleading
//because it does much more than that.
$size = getimagesize($pic);
//Now that you know the mime type, include it in the header.
header('Content-type: '.$size['mime']);
//Read the image and send it directly to the output.
readfile($pic);
}
?>
http://stackoverflow.com/questions/7069112/can-i-echo-a-jpg-image-through-php-without-processing-it – miki 2012-03-16 17:49:50
嘗試'的file_get_contents( '/內容/'。 $ pic);' – Ascherer 2012-03-16 17:54:26
對此我不是100%,但我認爲文件上傳必須是POST請求。簡單的參考。 http://www.w3schools.com/php/php_file_upload.asp – laymanje 2012-03-19 18:35:44