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
how to copy a photo from a given URL?
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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);
}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
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
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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
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