0

Is it possible to have PHP download a file from a remote server and save it in a local folder?

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.

5
  • What kind of file. We need to know. Commented Apr 14, 2012 at 6:02
  • 3
    Oh yeah and it is possible. you know that. Commented Apr 14, 2012 at 6:02
  • The file I want to download is a zip file. Commented Apr 14, 2012 at 6:03
  • Dupe. stackoverflow.com/questions/1006604/saving-file-using-curl Commented Apr 14, 2012 at 6:05
  • I tried searching before I posted but wasn't sure what to search for. Commented Apr 14, 2012 at 6:08

2 Answers 2

2
        <?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>";
    ?>
Sign up to request clarification or add additional context in comments.

Comments

1

Use file_get_contents.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.