Reputation: 2363
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.
Upvotes: 0
Views: 5062
Reputation: 14659
<?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>";
?>
Upvotes: 2