Page 1 of 1

get a jpeg from a website script?

Posted: Tue Jul 28, 2009 10:57 am
by mp04
Hey, I was wondering if someone can help me...

I need a php script that can goto a webpage that I specify, then find a *.jpg image IN A SPECIFIC folder I specify and then show it to me.

so basically it would goto

http://www.mysite.com/dailyimageshow
|
It would find the .jpg that is location at: http://www.mysite.com/images/dailyimages/2009//

and then grab that image onto another server without anything else.

is this possible? if so, how? (please note I am a newbie to programming, this is a project for church)

Re: get a jpeg from a website script?

Posted: Wed Jul 29, 2009 4:14 pm
by chinstroker
Does the image always have the same url?

If so, you can just use fopen($url, 'br') to get a handle on the data, then use fread() to either output it to the screen or save to a file.

If the url of the image changes, use $html = file_get_contents($urlOfPage) to get the html as a string, then use preg_match() using an appropriate pattern to search for to find the url of the image, then as above.

As ever, the PHP manual is your friend: php.net/fopen php.net/fread php.net/file_get_contents php.net/preg_match