function httpcopy($url, $file="", $timeout=60) {
    $file = empty($file) ? pathinfo($url,PATHINFO_BASENAME) : $file;
    $dir = pathinfo($file,PATHINFO_DIRNAME);
    !is_dir($dir) && @mkdir($dir,0755,true);
    $url = str_replace(" ","%20",$url);

    if(function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $temp = curl_exec($ch);
        if(@file_put_contents($file, $temp) && !curl_error($ch)) {
            return $file;
        } else {
            return false;
        }
    } else {
        $opts = array(
            "http"=>array(
            "method"=>"GET",
            "header"=>"",
            "timeout"=>$timeout)
        );
        $context = stream_context_create($opts);
        exit($url);
        if(@copy($url, $file, $context)) {
            //$http_response_header
            return $file;
        } else {
            return false;
        }
    }
}

  

;

PHP自定义函数: 下载远程文件的更多相关文章

  1. php自定义函数: 下载远程文件 httpcopy

    <?php function httpcopy($url, $file="", $timeout=60) { $file = empty($file) ? pathinfo( ...

  2. WPF下载远程文件,并显示进度条和百分比

    WPF下载远程文件,并显示进度条和百分比 1.xaml <ProgressBar HorizontalAlignment="Left" Height="10&quo ...

  3. java下载远程文件到本地

    java下载远程文件到本地(转载:http://www.cnblogs.com/qqzy168/archive/2013/02/28/2936698.html)   /**       * 下载远程文 ...

  4. PHP下载远程文件到指定目录

    PHP用curl可以轻松实现下载远程文件到指定目录: <?php class Download { public static function get($url, $file) { retur ...

  5. 使用CertUtil.exe下载远程文件

    使用CertUtil.exe下载远程文件 证书 https://www.cnblogs.com/17bdw/p/8728656.html 1.前言 经过国外文章信息,CertUtil.exe下载恶意软 ...

  6. 微信小程序开发 -- 通过云函数下载任意文件

    微信小程序开发 -- 通过云函数下载任意文件 1.云开发介绍 ​ 微信小程序开发者众所周知,小程序开发拥有许多限制,当我还是一个菜鸟入门的时候,第一关就卡在了没有备案域名的HTTP请求上面,那时候云开 ...

  7. 关于下载远程文件为未知文件.txt的解决方法

    本地下载文件后缀正常,服务器下载文件后缀都为.txt的解决方法: 后缀为 未知文件.txt 的原因为前端无权限获取Content-Disposition中的文件名 response.setHeader ...

  8. php自定义函数: 下载本地服务器的大文件

    // 使用方法 $file_path = './a.zip'; // 只能是本地服务器文件, 多大的文件都支持!! down_file($file_path); // 函数参数: 服务器文件路径,下载 ...

  9. php下载远程文件方法~

    直接上代码: getFile("http://easyread.ph.126.net/N8gDl6ayo5wLgKbgT21NZQ==/7917056565549478184.jpg&quo ...

随机推荐

  1. Java 7 新功能: 省略finally, 保证资源正常关闭

    class MyResource implements Closeable{ @Override public void close() throw IOException{ } } try( myR ...

  2. @classmethod, @staticmethod和@property这三个装饰器的使用对象是在类中定义的函数。下面的例子展示了它们的用法和行为:

    class MyClass(object): def __init__(self): self._some_property = "properties are nice" sel ...

  3. lodash 数组裁剪 drop

    _.drop(array, [n=1]) 裁剪数组中的前 N 个数组,返回剩余的部分. <!DOCTYPE html> <html lang="zh"> & ...

  4. spring 国际化-i18n

    i18n(其 来源是英文单词 internationalization的首末字符i和n,18为中间的字符数)是“国际化”的简称.在资讯领域,国际化(i18n)指让产品(出版 物,软件,硬件等)无需做大 ...

  5. 使用UIDatePicker

    什么是UIDatePicker 用官方文档的话来说,UIDatePicker就是使用多个滚轮来选择日期和时间的类.官方的示例有定时器,闹钟(设置时间)部件.正确设置后,UIDatePicker对象会在 ...

  6. 关于javaSocket中 Software caused connection abort: recv failed问题

    在学习Socket中今天突然遇到了以下这种问题 原来是网路连接出了问题,由于我測试的是远程连接所以是在学校的局域网下,结果非常不稳定,開始还以为怎么了一会连上了一会又出现故障然后把IP地址改为本机的1 ...

  7. 【leetcode】118. Pascal&#39;s Triangle

    @requires_authorization @author johnsondu @create_time 2015.7.23 19:54 @url [Pascal's Triangle](http ...

  8. linux系统下实时监控进程以及定位杀死挂起的进程

    一.实时监测进程 [root@instance-3lm099to ~]# top top - :: up days, min, users, load average: 0.01, 0.05, 0.0 ...

  9. 安装wamp后 异常Exception Exception in module wampmanager.exe at 000F15A0

    系统环境:Windows 2008 R2 64bit 安装环境:wampserver2.4-x64 按照正常windows安装程序,完成WAMP Server程序安装,安装完成启动WAMP Serve ...

  10. Problem A. Dynamic Grid

    Problem We have a grid with R rows and C columns in which every entry is either 0 or 1. We are going ...