Best way to get file from remote server and copy to local server using php

Let's say there is a file on a remote server that can be downloaded without any restrictions, i.e. you can put a direct link to the file in your browser and download the file, for example http://www.remotesite.com/video.avi will offer your browser to download this file. Using php, what is the best way to capture this file and upload it to a local server without uploading the file to my computer at all, what happens with phpBB if you put the url in the file upload form? You should also evaluate the example of the required code. Thanks

+7
source share
3 answers

Just use copy

 $source = "http://www.remotesite.com/video.avi"; $dest = "video.avi"; copy($source, $dest); 
+23
source
 $remote_file_contents = file_get_contents('http://remote_url/file/with.extension'); //Get the contents $local_file_path = 'your/local/path/to/the/file/with.extension'; file_put_contents($local_file_path, $remote_file_contents); //save the contents of the remote file 
+3
source

You can read and write a file without downloading a browser

 <?php $file = 'http://www.remotesite.com/video.avi'; // read the file from remote location $current = file_get_contents($file); // create new file name $name = "path/to/folder/newname.avi"; // Write the contents back to the file file_put_contents($file, $current); 
+2
source

All Articles