Page 1 of 1

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

Posted: Thu Apr 17, 2008 4:46 pm
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

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

Posted: Thu Apr 17, 2008 4:54 pm
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.

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

Posted: Thu Apr 17, 2008 5:06 pm
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

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

Posted: Fri Apr 18, 2008 3:54 am
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.