Copying Remote Images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vivekjain
Forum Commoner
Posts: 76
Joined: Thu Jan 08, 2004 12:38 am

Copying Remote Images

Post by vivekjain »

Hi,
I am trying to copy remote images from one server to another, but am getting this error:

Warning: copy(http://domainanme/image_name.jpg) [function.copy]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in


But if I try this from my local machine, it works fine, but from one remote server to another, it doesnt seem to work.

Any help would be much appreciated.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

file_get_contents() + file_put_contents() (or a similar set of functionality if you aren't running php 5)
vivekjain
Forum Commoner
Posts: 76
Joined: Thu Jan 08, 2004 12:38 am

Remote Image Copying

Post by vivekjain »

Hi,
Thanks for your reply. I tried that, but getting the same problem.
This is the image that I am trying to copy:

http://www.picklesandloop.com/images/pr ... e/_MG_0060 400x550.jpg

Of course, for images on other remote servers, we are able to copy images, but not for the one above.

Thanks
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

WHOA 8O

Nice site... 8) :twisted:

I'm surprised no one has questioned your motives...using those images on your own site without permission...is a bad thing called image burning...or hotlinking, etc...

Naughty naughty...like those girls on the homepage :P

They might have some kind of prevention mechanism built into the site to prevent such a thing...your likely SOL buddy ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's quite possible their server has active denials based on all sorts of information. You may need to use cURL.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Code: Select all

$ch = curl_init ($url . $filename);
$fp = fopen ($directory . $filename, "w");
curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
fclose ($fp);
$url = the url to copy from IE: http://www.mine.com/images/
$filename = the name of the image file to copy
$directory = the directory path to save the image IE: /home/mysite/newimages/

That should do it.
Post Reply