Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy file from remote server or URL [duplicate]

Tags:

file

php

copy

I have the following code:

$file = 'http://3.bp.blogspot.com/-AGI4aY2SFaE/Tg8yoG3ijTI/AAAAAAAAA5k/nJB-mDhc8Ds/s400/rizal001.jpg'; $newfile = '/img/submitted/yoyo.jpg';  if ( copy($file, $newfile) ) {     echo "Copy success!"; }else{ echo "Copy failed."; } 

and it always output "Copy failed"

copy(/img/submitted/yoyo.jpg) [function.copy]: failed to open stream: No such file or directory 

my directory is set to 777.

any ideas? thanks!

like image 542
Kris Avatar asked Mar 23 '12 17:03

Kris


People also ask

How copy file from remote server to another remote server?

The scp tool relies on SSH (Secure Shell) to transfer files, so all you need is the username and password for the source and target systems. Another advantage is that with SCP you can move files between two remote servers, from your local machine in addition to transferring data between local and remote machines.

How copy data from remote server?

You can use SecureShell (SSH) or Remote Sync (Rsync) to transfer files to a remote server. Secure Copy (SCP) uses SSH to copy only the files or directories that you select. On first use, Rsync copies all files and directories and then it copies only the files and directories that you have changed.


1 Answers

While copy() will accept a URL as the source argument, it may be having issues a url for the destination.

Have you tried specifying the full filesystem path to the output file? I'm assuming you're not trying to put the new file onto a remote server.

For example:

$file = 'http://3.bp.blogspot.com/-AGI4aY2SFaE/Tg8yoG3ijTI/AAAAAAAAA5k/nJB-mDhc8Ds/s400/rizal001.jpg'; $newfile = $_SERVER['DOCUMENT_ROOT'] . '/img/submitted/yoyo.jpg';  if ( copy($file, $newfile) ) {     echo "Copy success!"; }else{     echo "Copy failed."; } 

The above worked nicely for me.

like image 115
Mark Biek Avatar answered Sep 20 '22 14:09

Mark Biek