Hi,
I am trying to come up with a snippet that will fetch an image off a remote server, and copy it to a local folder. The format it will most often be in is: http://somewhere.com:8080/pic_1.jpg
Should I use something like fsockopen?
Thanks,
Cbcb
Fetch remote images
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
if file URL wrappers are on at your server, which they likely are, you can use file_get_contents() or any of the other file functions to get the file.
fsockopen() is a bit more complicated to fetch a remote file with, unless you don't have file URL wrappers enabled..
fsockopen() is a bit more complicated to fetch a remote file with, unless you don't have file URL wrappers enabled..
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
wow.. really old version.. you should be able to use the fopen()/fread()/fclose() combination then.
example:
example:
Code: Select all
$fp = fopen($url);
if(!$fp)
die('unabled to load file');
$buf = '';
while(!feof($fp))
{
$buf .= fread($fp, 1024);
}
fclose($fp);
echo $buf;