<i id='vQyTA'><tr id='vQyTA'><dt id='vQyTA'><q id='vQyTA'><span id='vQyTA'><b id='vQyTA'><form id='vQyTA'><ins id='vQyTA'></ins><ul id='vQyTA'></ul><sub id='vQyTA'></sub></form><legend id='vQyTA'></legend><bdo id='vQyTA'><pre id='vQyTA'><center id='vQyTA'></center></pre></bdo></b><th id='vQyTA'></th></span></q></dt></tr></i><div id='vQyTA'><tfoot id='vQyTA'></tfoot><dl id='vQyTA'><fieldset id='vQyTA'></fieldset></dl></div>
    <legend id='vQyTA'><style id='vQyTA'><dir id='vQyTA'><q id='vQyTA'></q></dir></style></legend>

    • <bdo id='vQyTA'></bdo><ul id='vQyTA'></ul>

      <small id='vQyTA'></small><noframes id='vQyTA'>

    1. <tfoot id='vQyTA'></tfoot>

      使用 PHP 下载远程文件到服务器

      Download Remote File to Server with PHP(使用 PHP 下载远程文件到服务器)
    2. <tfoot id='a2loc'></tfoot>
      <i id='a2loc'><tr id='a2loc'><dt id='a2loc'><q id='a2loc'><span id='a2loc'><b id='a2loc'><form id='a2loc'><ins id='a2loc'></ins><ul id='a2loc'></ul><sub id='a2loc'></sub></form><legend id='a2loc'></legend><bdo id='a2loc'><pre id='a2loc'><center id='a2loc'></center></pre></bdo></b><th id='a2loc'></th></span></q></dt></tr></i><div id='a2loc'><tfoot id='a2loc'></tfoot><dl id='a2loc'><fieldset id='a2loc'></fieldset></dl></div>

      <legend id='a2loc'><style id='a2loc'><dir id='a2loc'><q id='a2loc'></q></dir></style></legend>
      • <small id='a2loc'></small><noframes id='a2loc'>

          <bdo id='a2loc'></bdo><ul id='a2loc'></ul>

                  <tbody id='a2loc'></tbody>

                本文介绍了使用 PHP 下载远程文件到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                过去两天我一直在四处寻找并尝试了所有方法,但仍然无法正常工作.我觉得这应该是一件比较简单的事情.

                I've been looking all over the place for the last two days and trying everything and still can't get anything to work. I feel like this should be a relatively simple thing to do.

                我想要做的就是将远程文件从 URL 下载到我服务器上的目录.

                All I want to do is download a remote file from a URL to a directory on my server.

                例如,如果

                $_url = http://www.freewarelovers.com/android/download/temp/1306495040_Number_Blink_1.1.1.apk
                

                $_dir =/www/downloads/

                然后当一切都说完了我想要1306495040_Number_Blink_1.1.1.apk/www/downloads/

                Then when all is said and done I want 1306495040_Number_Blink_1.1.1.apk in /www/downloads/

                我试过 copy() 函数,我试过

                I've tried the copy() function, I've tried

                file_put_contents("$_dir.$_file_name", file_get_contents($_url));
                

                并得到以下错误:

                file_get_contents(): 无法打开流:HTTP 请求失败!

                推荐答案

                应该这样做:

                set_time_limit(0);
                
                $url = 'http://www.freewarelovers.com/android/download/temp/1306495040_Number_Blink_1.1.1.apk';
                $file = fopen(dirname(__FILE__) . '/downloads/a.apk', 'w+');
                
                $curl = curl_init();
                
                // Update as of PHP 5.4 array() can be written []
                curl_setopt_array($curl, [
                    CURLOPT_URL            => $url,
                //  CURLOPT_BINARYTRANSFER => 1, --- No effect from PHP 5.1.3
                    CURLOPT_RETURNTRANSFER => 1,
                    CURLOPT_FILE           => $file,
                    CURLOPT_TIMEOUT        => 50,
                    CURLOPT_USERAGENT      => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'
                ]);
                
                $response = curl_exec($curl);
                
                if($response === false) {
                    // Update as of PHP 5.3 use of Namespaces Exception() becomes Exception()
                    throw new Exception('Curl error: ' . curl_error($curl));
                }
                
                $response; // Do something with the response.
                

                这篇关于使用 PHP 下载远程文件到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <small id='2Yx5l'></small><noframes id='2Yx5l'>

                  <legend id='2Yx5l'><style id='2Yx5l'><dir id='2Yx5l'><q id='2Yx5l'></q></dir></style></legend>
                    <tbody id='2Yx5l'></tbody>

                    <tfoot id='2Yx5l'></tfoot>
                      <i id='2Yx5l'><tr id='2Yx5l'><dt id='2Yx5l'><q id='2Yx5l'><span id='2Yx5l'><b id='2Yx5l'><form id='2Yx5l'><ins id='2Yx5l'></ins><ul id='2Yx5l'></ul><sub id='2Yx5l'></sub></form><legend id='2Yx5l'></legend><bdo id='2Yx5l'><pre id='2Yx5l'><center id='2Yx5l'></center></pre></bdo></b><th id='2Yx5l'></th></span></q></dt></tr></i><div id='2Yx5l'><tfoot id='2Yx5l'></tfoot><dl id='2Yx5l'><fieldset id='2Yx5l'></fieldset></dl></div>

                          <bdo id='2Yx5l'></bdo><ul id='2Yx5l'></ul>