此示例代码片段应该按照您的要求进行操作。如果在服务器上启用了魔术引号,我还包含了代码去除斜杠。这将使您的代码更加便携,并且与未来版本的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