zoukankan      html  css  js  c++  java
  • php获取远程文件内容的函数

    一个简单的php获取远程文件内容的函数代码,兼容性强。直接调用就可以轻松获取远程文件的内容,使用这个函数也可获取图片。代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    /**
     
     * 读远程内容
     
     * @return string
     
     */
    function get_url_content($url){
     
      if(function_exists("curl_init")){
     
        $ch = curl_init();
     
        $timeout = 30;
     
        curl_setopt($ch, CURLOPT_URL, $url);
     
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
     
        $file_contents = curl_exec($ch);
     
        curl_close($ch);
     
      }else{
     
        $is_auf=ini_get('allow_url_fopen')?true:false;
     
        if($is_auf){
     
          $file_contents = file_get_contents($url);
     
        }
     
      }
     
      return $file_contents;
     
    }

    以上就是php获取远程文件内容的函数代码,希望这篇文章对大家学习php程序设计有所帮助。

  • 相关阅读:
    鼠标事件:
    各种坑记录
    Go学习笔记
    Scala学习笔记-7-代码片段
    Go学习笔记
    NIO学习笔记
    Redis常用操作
    docker & k8s 笔记
    Node常用笔记
    Maven常用笔记
  • 原文地址:https://www.cnblogs.com/shaoguan/p/6515276.html
Copyright © 2011-2022 走看看