HI,
Please excuse if similar issue has been posted earlier.
I want to check if a remote image exists or not.
say if url is http://example/image.png
and no image exists there, then...??
Earlier I was using @getimagesize function, but later on found this comment saying that it makes server slow for on large images.
http://www.php.net/manual/en/function.g ... .php#88793
I don't know if the solution mentioned in that comment is correct rather efficient?
Is there any other efficient, fast, small solution for this?
Thanks in advance...
Regards
Is getimagesize efficient??
Moderator: General Moderators
- rupam_jaiswal
- Forum Newbie
- Posts: 22
- Joined: Thu Jun 05, 2008 12:54 am
Re: Is getimagesize efficient??
I'd say just open a socket and instead of actually downloading the image file, just download the header and see if you get a "200 OK" response. Optionally also follow 301/302 redirects, depending on whether this meets your definition of "exists".
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Is getimagesize efficient??
I prefer cURL with the CURLOPT_NOBODY option. No need to mess with HTTP protocols.Apollo wrote:I'd say just open a socket and instead of actually downloading the image file, just download the header and see if you get a "200 OK" response. Optionally also follow 301/302 redirects, depending on whether this meets your definition of "exists".
Re: Is getimagesize efficient??
Simplest might be to use file_exists()
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Is getimagesize efficient??
Yeah but does that work on URLs too? (TS mentioned remote files)pickle wrote:Simplest might be to use file_exists()
Re: Is getimagesize efficient??
It does if URL wrappers are on - and I think by default they are.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.