Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-01-2004, 08:50 PM   PM User | #1
AaronW
Senior Coder

 
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 1,223
Thanks: 0
Thanked 0 Times in 0 Posts
AaronW is an unknown quantity at this point
Verify the existance of a URL?

I've got a field that takes a URL in the form of 'http://.../somefile.jpg' (without quotes) and I'd like to somehow check that the URL to the image they've provided returns an actual image file. Is there any other way to do this, other than fopen ($_POST['url'])? Even using fopen(), would I be able to assure that the file returned is actually a JPEG?

Any suggestions would be greatly appreciated. In the meantime, I'll just allow broken URLs.

Thanks,
Aaron
__________________
offtone.com | offtonedesign.com
AaronW is offline   Reply With Quote
Old 10-02-2004, 03:35 AM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,912
Thanks: 5
Thanked 80 Times in 79 Posts
firepages will become famous soon enough
I think fopen() ,file() or file_get_contents() etc is the quickest way , as to the mime-type there is no way you can check this until you have the file on your system (other than simply assuming the extension is correct!) as you can't perform file operations on remote files.
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 10-02-2004, 04:40 AM   PM User | #3
jamescover
Regular Coder

 
Join Date: Aug 2002
Location: USA
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
jamescover is an unknown quantity at this point
Quote:
Originally Posted by AaronW
I've got a field that takes a URL in the form of 'http://.../somefile.jpg' (without quotes) and I'd like to somehow check that the URL to the image they've provided returns an actual image file.

If you mean a form field, check out these threads:


http://www.codingforums.com/showthread.php?t=45398


http://www.codingforums.com/showthread.php?t=45438


-james
__________________
"God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "
jamescover is offline   Reply With Quote
Old 10-02-2004, 11:39 AM   PM User | #4
ReadMe.txt
Regular Coder

 
Join Date: Jun 2002
Location: Sheffield, UK
Posts: 552
Thanks: 0
Thanked 0 Times in 0 Posts
ReadMe.txt is an unknown quantity at this point
getimagesize()

Exactly what you are looking for.
__________________
"To be successful in IT you don't need to know everything - just where to find it in under 30 seconds"

(Me Me Me Me Me Me Me Me Me)
ReadMe.txt is offline   Reply With Quote
Old 10-02-2004, 12:53 PM   PM User | #5
AaronW
Senior Coder

 
Join Date: Feb 2003
Location: Ontario, Canada
Posts: 1,223
Thanks: 0
Thanked 0 Times in 0 Posts
AaronW is an unknown quantity at this point
Ah! That's right! getimagesize () can do remote files. Sweet. Thanks

Thanks to the others, too. And they aren't uploading the file, they're just typing a URL.
__________________
offtone.com | offtonedesign.com
AaronW is offline   Reply With Quote
Old 10-02-2004, 02:02 PM   PM User | #6
jamescover
Regular Coder

 
Join Date: Aug 2002
Location: USA
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
jamescover is an unknown quantity at this point
Quote:
Originally Posted by AaronW
Thanks to the others, too. And they aren't uploading the file, they're just typing a URL.
Same difference.



-james
__________________
"God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "
jamescover is offline   Reply With Quote
Old 10-02-2004, 03:29 PM   PM User | #7
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,912
Thanks: 5
Thanked 80 Times in 79 Posts
firepages will become famous soon enough
Quote:
Originally Posted by ReadMe.txt
getimagesize()

Exactly what you are looking for.

ok! well that shuts me up , well spotted
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:36 AM.


Advertisement
Log in to turn off these ads.