Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to get a file from remote server and copy to local server using php [closed]

Let's say there is a file on a remote server that can be downloaded without any restrictions, ie. you can put the direct link to the file in your browser and it downloads the file, for example http://www.remotesite.com/video.avi will prompt your browser to download that file. Using php, what is the best way to grab that file and upload it to my local server without the file being downloaded to my PC at all, which is what happens with phpBB if you put a url in the file upload form? An example of the code needed would also be appreciated. Thanks

like image 846
Jizbo Jonez Avatar asked May 13 '13 08:05

Jizbo Jonez


People also ask

How do I transfer files from a remote server to a local machine?

scp command is being used to copy files from a remote server to a local machine and vice versa. It uses ssh to do secure file transfer.

How can download file from server to local machine in PHP?

You can download any type of file (image, ZIP, video, audio, etc) from the remote server using PHP. Use the readfile() function with application/x-file-to-save Content-type header, to download a ZIP file from remote URL using PHP. header("Content-type: application/x-file-to-save");

Can you transfer a file from the remote machine to the local machine?

Once you have remotely access the computer over RDP, you can use copy and paste to transfer files from remote machine to your local machine effortlessly.


2 Answers

Just use copy

$source = "http://www.remotesite.com/video.avi";
$dest = "video.avi";
copy($source, $dest);
like image 76
Baba Avatar answered Sep 20 '22 15:09

Baba


$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
like image 22
Elavarasan Muthuvalavan - Lee Avatar answered Sep 22 '22 15:09

Elavarasan Muthuvalavan - Lee