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!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With