Viewed   114 times

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!

 Answers

5

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.

Sunday, October 2, 2022
3

If you have PHP5 and the HTTP stream wrapper enabled on your server, it's incredibly simple to copy it to a local file:

copy('http://somedomain.com/file.jpeg', '/tmp/file.jpeg');

This will take care of any pipelining etc. that's needed. If you need to provide some HTTP parameters there is a third 'stream context' parameter you can provide.

Saturday, December 3, 2022
1

I'd guess that you are on windows and that you have I: mapped to a share such as \server2files ...

If so, that's your problem. These mappings are only avaialble to the current users (eg, the admin account), not to the IUSR account that your php is probably running as (assuming IIS). Solution, don't use mappings, instead use the full 'unc' path name, ie '\serversharefolderfile.ext', also remember that the IUSR account will need access to these shares/folders/files

Monday, October 3, 2022
1

You can create a run of the mill curl script that connects to a remote server and fetches data, inserts into your db, set limits and exceptions. Then create an entry in crontab to run this script every 10 minutes. I have a similar setup running for one of my website which fetches data from stock exchange and updates a local cache, another script has the task of consuming the cache as and when required.

Saturday, December 17, 2022
 
3

Ok I think I found a solution, I did following:

exec('copy ' $in . ' ' . $out);

This copied the whole file properly.

I am not sure why exactly this works.

My wild guess would be that copy() copies files immediately even if there a some changes and the command probably waits until there are no changes.

Wednesday, September 28, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :