473,381 Members | 1,509 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 software developers and data experts.

[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 2960

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ywg | last post by:
I'm generating an image using several PHP image routines: imagecreatefromjpeg, imagejpeg, etc. The PHP file containing these routines is meant to be included on web pages just like regular...
3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
22
by: Olaf Noehring | last post by:
Hi does anyone of you know a save method on PHP to relyably, maybe using other programs create scrennshots (thumbnails) of websites? I am the administrator of the open source project (at...
5
by: DaveB | last post by:
I have to come up to speed quickly on PHP since I have been given the responsibilty of updating our website. I have setup a local web server through IIS, downloaded and installed PHP. I'm using...
3
by: Phil Lamey | last post by:
Hi Folks, I have run into a bit of an issue with checking for files. Some files reside on Server X and some on Server Y. The page with all the links is on Server X. If the file exists we...
12
by: Troy | last post by:
My ISP provides me with 2 servers: one for normal web hosting (non-PHP) and a CGI server (with PHP). I create my website using fusion 7 and upload this in its entirity to the web hosting server....
2
by: EMW | last post by:
Hi, My ASPX (vb.NET) page needs to check an URL. if it exists then it shows the picture (url is to that picture) if is doesn't exist, it must show another picture. but the question is how do...
8
by: Marcel | last post by:
I have a problem with a PHP page that seems to get executed twice. I am running PHP5 ISAPI on 2003 server. The script is a PHP page with a form. When the form is submitted one record have to...
3
clintw
by: clintw | last post by:
My problem. I have a html contact form that is being spammed. So I have set .html to be treated as .php, in order to include php image verification into the form. However, the Action on the form...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.