468,247 Members | 1,317 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,247 developers. It's quick & easy.

[PHP] Checking if an image exists on a remote server.

Hi.
I want to check if an image exists on a remote server, and if it does,
show it. I
If it does not exist I want to show a default message. I have
previously used these chunks of code but none of them have worked. Any
Ideas?

------------------------
$imgCheck=readfile("http.//www.somesite.com/image.gif");
if($imgCheck) echo "<img border=0
src=\"http.//www.somesite.com/image.gif\" width=\"550\" height=\"80\"
alt=\"banner\">";
-------------------------
$fp = @fopen("http.//www.somesite.com/image.gif","r");
if ($fp) {
echo '<img border=0 src="http.//www.somesite.com/image.gif" width="550"
height="80" alt="banner">';
} else { echo 'Resource not valid'; }
------------------------
Thanks ;o

May 23 '06 #1
6 2804

da*********@gmail.com wrote:
Hi.
I want to check if an image exists on a remote server, and if it does,
show it. I
If it does not exist I want to show a default message. I have
previously used these chunks of code but none of them have worked. Any
Ideas?

------------------------
$imgCheck=readfile("http.//www.somesite.com/image.gif");
if($imgCheck) echo "<img border=0
src=\"http.//www.somesite.com/image.gif\" width=\"550\" height=\"80\"
alt=\"banner\">";
-------------------------
$fp = @fopen("http.//www.somesite.com/image.gif","r");
if ($fp) {
echo '<img border=0 src="http.//www.somesite.com/image.gif" width="550"
height="80" alt="banner">';
} else { echo 'Resource not valid'; }
------------------------
Thanks ;o


Dunno if that's it, but in your code you have
HTTP.//
instead of
HTTP://

Frizzle.

May 23 '06 #2
Haha, no it isn't, ;)
It was my fault because I typoed the http:// when writing the message
onto the newsgroup lol. Sorry for that. I wrote that because I wanted
to hide the URL.

May 23 '06 #3
Bump!

May 30 '06 #4
Bump!

May 30 '06 #5
Rik
da*********@gmail.com wrote:
Bump!


Tsssk....
But: if it doesn't work, why surpress error-messages?
Turn off error-surpressing, put error_reporting(E_ALL) in your script, and
me thinks you'll find the answer.

Probably has something to do with allow_url_fopen.

Grtz,
--
Rik Wasmus
May 30 '06 #6
da*********@gmail.com wrote:
Hi.
I want to check if an image exists on a remote server, and if it does,
show it. I
If it does not exist I want to show a default message. I have
previously used these chunks of code but none of them have worked. Any
Ideas?

------------------------
$imgCheck=readfile("http.//www.somesite.com/image.gif");
if($imgCheck) echo "<img border=0
src=\"http.//www.somesite.com/image.gif\" width=\"550\" height=\"80\"
alt=\"banner\">";
-------------------------
$fp = @fopen("http.//www.somesite.com/image.gif","r");
if ($fp) {
echo '<img border=0 src="http.//www.somesite.com/image.gif" width="550"
height="80" alt="banner">';
} else { echo 'Resource not valid'; }
------------------------
Thanks ;o


readfile() won't work because it echoes the output to the user (unless you've
buffered it).

fopen() should work, though.

It would help if you told us what happens when you try.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 30 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by ywg | last post: by
3 posts views Thread by dave | last post: by
22 posts views Thread by Olaf Noehring | last post: by
5 posts views Thread by DaveB | last post: by
3 posts views Thread by Phil Lamey | last post: by
12 posts views Thread by Troy | last post: by
2 posts views Thread by EMW | last post: by
8 posts views Thread by Marcel | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.