get a jpeg from a website script?

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
mp04
Forum Newbie
Posts: 16
Joined: Fri Dec 26, 2008 9:52 pm

get a jpeg from a website script?

Post 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)
chinstroker
Forum Newbie
Posts: 5
Joined: Sun Apr 26, 2009 3:01 pm

Re: get a jpeg from a website script?

Post 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
Post Reply