Get Remote Image (like fopen())

software development


Basically, I want to grab an image from and write it to a directory. Simple enough.

I looked at the info at, which proved to be worthless to me.

When I put the following code into a page and run it, I get a new file called “example_htmlpage.html” written in my directory. Cool.

<?php $ch = curl_init(""); $fp = fopen("example_htmlpage.html", "w"); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); fclose($fp); ?>

I made a couple of changes to attempt to fetch an image from, and sure enough it didn’t work.

I’m very new to the CURL stuff (but not new to PHP), so I’m sure it’s user error. I’d much rather use fopen(), fwrite(), etc…

Does anyone have a simple code solution (that will work on DreamHost) where I can fetch a JPG image from my own AXIS 207w webcam in my apartment and save the image (called image.jpg) in a directory on my web site?

Thanks in advance for any helpful input.



My suggestion to you would be to ditch the Curl. PHP has built in FTP functionality. I have a script that pushes files out to multiple domains and I nearly tore my hair out trying to use Curl.

If you have an FTP server set up on your local machine/network , you should be able to connect to it and grab the file that way. The manual was really helpful to me.

Good luck.

Angela Gann
CrimsonDryad Web Design Services
Web Design, Custom Software Development