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()打开网页后,返回的是一个字符串,可以直接输出的。

相关文章:

  • 2022-12-23
  • 2021-07-14
  • 2021-12-16
  • 2022-12-23
  • 2021-06-15
  • 2021-07-07
  • 2021-12-22
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-26
  • 2021-11-08
  • 2022-01-08
  • 2021-06-19
  • 2021-12-07
相关资源
相似解决方案