By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,738 Members | 1,800 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,738 IT Pros & Developers. It's quick & easy.

capture images remotely with PHP

P: n/a
Hi everyone !

I am just wondering if capturing an image remotely with php is
doable ?

I am working on a project for my department where I need to write php
code to capture an remote image and save it to a local folder/web site
directory given an image's URL.

Have anyone done anything like this ? If you have, do you mind share
your ideas/sample code ?

Thank you in advance,

Josh

Feb 3 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ar********@yahoo.com wrote:
Hi everyone !

I am just wondering if capturing an image remotely with php is
doable ?

I am working on a project for my department where I need to write php
code to capture an remote image and save it to a local folder/web site
directory given an image's URL.

Have anyone done anything like this ? If you have, do you mind share
your ideas/sample code ?
This will work in PHP 4.3.0 and above, and if allow_url_fopen is
enabled:

<?php
$img = imagecreatefromjpeg("http://example.com/path/to/image.jpg");
imagejpeg($img, "localimage.jpg");
?>

Alternately, if image functions are disabled, this might work:

<?php
$imagedata = file_get_contents("http://example.com/path/to/image.jpg");
$newfile = fopen("localimage.jpg", "w");
fwrite($newfile, $imagedata);
fclose($newfile);
?>

--
Kim André Akerĝ
- ki******@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
Feb 3 '07 #2

P: n/a
On Feb 2, 4:05 pm, artlove...@yahoo.com wrote:
Hi everyone !

I am just wondering if capturing an image remotely with php is
doable ?

I am working on a project for my department where I need to write php
code to capture an remote image and save it to a local folder/web site
directory given an image's URL.

Have anyone done anything like this ? If you have, do you mind share
your ideas/sample code ?

Thank you in advance,

Josh

If by "capturing an image remotely" you mean download and image from
another website and store it locally, you have a couple of options.
Both of these can be very simple depending on the configuration of
your php installation.

1. If allow_url_fopen is enabled on your machine, you can simply use
fopen to download the image, and use the resulting file handle to copy
the data to wherever you wish.
http://www.php.net/fopen : see the comment made on '22-Jan-2007
02:34', which, If i understood you correctly, does exactly what you
want.

2. Slightly more complex, but if your php installation supports curl
you can simply use curl to fetch the remote data.
http://www.php.net/curl

Carl.

Feb 3 '07 #3

P: n/a
Thank you all so much for your helpful tips and directions.

Jay

On Feb 2, 4:44 pm, "Carl" <c.gro...@gmail.comwrote:
On Feb 2, 4:05 pm, artlove...@yahoo.com wrote:
Hi everyone !
I am just wondering if capturing an image remotely with php is
doable ?
I am working on a project for my department where I need to write php
code to capture anremoteimage and save it to a local folder/web site
directory given an image's URL.
Have anyone done anything like this ? If you have, do you mind share
your ideas/sample code ?
Thank you in advance,
Josh

If by "capturing an image remotely" you mean download and image from
another website and store it locally, you have a couple of options.
Both of these can be very simple depending on the configuration of
your php installation.

1. If allow_url_fopen is enabled on your machine, you can simply use
fopen to download the image, and use the resulting file handle to copy
the data to wherever you wish.http://www.php.net/fopen: see the comment made on '22-Jan-2007
02:34', which, If i understood you correctly, does exactly what you
want.

2. Slightly more complex, but if your php installation supports curl
you can simply use curl to fetch theremotedata.http://www.php.net/curl

Carl.

Feb 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.