You often need to use the remote attachment function to write the collector's publishing interface, so you have written a function for remotely downloading files from PHP to a local place. This function is usually enough. if the server supports the CURL function, the program will give priority to CURL. if you need it, you can refer to it. The code is very simple, so it won't be too much nonsense. we will provide it directly:
array( "method"=>"GET", "header"=>"", "timeout"=>$timeout) ); $context = stream_context_create($opts); if(@copy($url, $file, $context)) { //$http_response_header return $file; } else { return false; } }}?>
Another remote download file to the server
< ?php// maximum execution time in secondsset_time_limit (24 * 60 * 60);if (!isset($_POST['submit'])) die();// folder to save downloaded files to. must end with slash$destination_folder = 'temp/'; $url = $_POST['url'];$newfname = $destination_folder . basename($url);$file = fopen ($url, "rb");if ($file) {$newf = fopen ($newfname, "wb");if ($newf)while(!feof($file)) {fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );}}if ($file) {fclose($file);}if ($newf) {fclose($newf);}?>
The above is all the content of this article. I hope you will like it.
For more articles about how to remotely download files from PHP to a local machine, refer to the PHP Chinese website!