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

  • 相关阅读:
    oracle常用命令
    批量导出docker镜像
    python中的xpath
    __call__, __str__
    闭包
    ORM操作
    nginx跨域请求
    docker-compose命令
    nginx 之 websocket长连接
    nginx--proxy_set_header
  • 原文地址:https://www.cnblogs.com/hanshuai0921/p/7416851.html
Copyright © 2011-2022 走看看