Page 1 of 1

how to copy a photo from a given URL?

Posted: Mon Aug 29, 2005 11:32 am
by jasongr
Hello

I am given a URL to a photo on some server
I would like to write a script that copies that photo into some folder in my own server
Can anyone suggests a method to doing that?

regards

Posted: Mon Aug 29, 2005 11:38 am
by feyd

Code: Select all

// assume $url is the remote file url
$fp = fopen('/your/path/'.basename($url),'wb');
if(!$fp)
{
  fwrite($fp, file_get_contents($url));
  fclose($fp);
}

Posted: Mon Aug 29, 2005 12:03 pm
by jasongr
Here is a more detailed explanation

All the URLs in this example are fictious

I am now running in http://1.1.1.1/a.php

this file should copy somehow a photo that resides in a specific folder under the http://1.1.1.1/ URL into another specific folder
in a different server at http://2.2.2.2/
For example, photo http://1.1.1.1/Photos/1.jpg needs to be copied to http://2.2.2.2/OtherPhotos/1.jpg

I thought about having http://1.1.1.1/a.php trigger some php file in http://2.2.2.2/ like http://2.2.2.2/b.php
passing to it the URL of the photo that needs to be copied.
For example: http://2.2.2.2/b.php?url=http://1.1.1.1/Photos/1.jpg

b.php will then copy the photo from http://1.1.1.1/ to the correct folder in http://2.2.2.2/

The problem is that I need to the flow of the code to continue in http://1.1.1.1/a.php after the copying takes place
Is this possible?

regards

Posted: Mon Aug 29, 2005 12:21 pm
by John Cartwright
Why not use ftp?
Correct me if I'm wrong, but it sounds like your stealing someone's images. :?

Posted: Mon Aug 29, 2005 1:12 pm
by feyd
the posted code allows for such a thing, as it illustrates..

Posted: Mon Aug 29, 2005 2:20 pm
by m3mn0n
Maybe he's building a Google Image Search clone. =P

Posted: Tue Aug 30, 2005 1:09 am
by jasongr
I found a solution using file_get_contents

I am actually writing this as a fix to my code
I have code that resides on one of my server that does image processing. The code expects the image to be
local on the same machine it is at
However the invoking code may run on some other server, so I need some way to copy an image that the user uploads
from one server to the server on which the image processing code is at

I am not stealing any images

thanks for the help

Posted: Tue Aug 30, 2005 7:44 am
by feyd
can we mark this solved jasongr?