简体   繁体   English

PHP自动下载文件

[英]PHP automatically download file

Is it possible to have PHP download a file from a remote server and save it in a local folder? PHP是否可以从远程服务器下载文件并将其保存在本地文件夹中?

EDIT 编辑

I didn't know this was a duplicate question. 我不知道这是一个重复的问题。 Before posting I did search, but was searching for "php automatically download file" and was getting results on how to force a browser to download a file instead of opening it. 发布之前,我进行了搜索,但是正在搜索“ php自动下载文件”,并获得有关如何强制浏览器下载文件而不是打开文件的结果。

        <?php
    // set url "http://
           curl_setopt($ch, CURLOPT_URL, "<your url>"); 

          //return the transfer as a string 
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

         // $output contains the output string 
         $output = curl_exec($ch); 

         // close curl resource to free up system resources 
          curl_close($ch); 

    file_put_contents($output,"<file>";
    ?>

使用file_get_contents

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM