php请求图片,PHP - 发送GET请求并获取图片作为回报

此示例代码段应该按照您的要求执行。如果在服务器上启用魔术引号,我还包括仅剥离斜线的代码。这将使您的代码更具可移植性,并与未来版本的PHP兼容。我还添加了getimagesize()来检测MIME类型,以便为图像输出正确的标题,而不必假设它是特定类型。

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);

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值