Download an Image (php generated not a direct image link)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php_ghost
Forum Commoner
Posts: 55
Joined: Thu Jan 11, 2007 3:29 am

Download an Image (php generated not a direct image link)

Post by php_ghost »

Hi guys,

I have this script under my localhost. I want the script to download an image from a website without undergoing the "save as" dialog box as I have lots of images to download. the problem is that, the images on the page are not a direct link to the image file but rather embedded in a php file (ex. display_image.php?image=image_800.jpg). I've tried several methods but the closest I got was to download the .php file. And even if I rename the files to *.jpg, I got no image displayed.

TIA,
Archie
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Download an Image (php generated not a direct image link)

Post by onion2k »

If the image won't display then there's a bug in the script. We can't help you debug it without seeing the source.
php_ghost
Forum Commoner
Posts: 55
Joined: Thu Jan 11, 2007 3:29 am

Re: Download an Image (php generated not a direct image link)

Post by php_ghost »

the image displays correctly in my browser when I use it like

Code: Select all

<img src="http://blahblah.com/display_image.php?image=image_800.jpg" />
. However, when I download the image using php, I can only download the display_image.php file and even if I replace the extension to a .jpg, i get a blank jpg file.

Thanks,
Archie
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Download an Image (php generated not a direct image link)

Post by onion2k »

Sounds like you're not passing the request through Apache. The script needs to run in order for you to save the output of it, if you try to save it by accessing it through the file system it won't run, the file system will just open the file. If you're doing, for example, file_get_contents("display_image.php?image=image_800.jpg") try using file_get_contents("http://localhost/path/to/your/code/disp ... ge_800.jpg") instead. Though you will need url_wrappers turned on in php.ini for that to work.
Post Reply