php读取url连接的图片,输出到浏览器

 header('Content-Type: application/pdf'); // PDF文件
            $fp = fopen($ret->url, "rb"); //二进制方式打开文件
                fpassthru($fp); // 输出至浏览器
                exit;

如果是图片,就修改header头

header('Content-Type: text/html; charset=utf-8'); //网页编码
15 header('Content-Type: text/plain'); //纯文本格式
16 header('Content-Type: image/jpeg'); //JPG、JPEG 
17 header('Content-Type: application/zip'); // ZIP文件
18 header('Content-Type: application/pdf'); // PDF文件
19 header('Content-Type: audio/mpeg'); // 音频文件 
20 header('Content-type: text/css'); //css文件
21 header('Content-type: text/javascript'); //js文件
22 header('Content-type: application/json'); //json
23 header('Content-type: application/pdf'); //pdf
24 header('Content-type: text/xml'); //xml
25 header('Content-Type: application/x-shockw**e-flash'); //Flash动画

fopen打开文件后得到不是字符串,不能直接输出要fgets()这个函数获取字符串,fgets()函数是从文件指针中读取一行。文件指针必须是有效的,必须指向由 fopen() 或 fsockopen() 成功打开的文件(并还未由 fclose() 关闭)。

file_get_contents()打开网页后,返回的是一个字符串,可以直接输出的。

转载于:https://www.cnblogs.com/hanshuai0921/p/7416851.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值