Forum Moderators: coopster

Message Too Old, No Replies

displaying broken image

         

generic

6:05 am on Jan 25, 2005 (gmt 0)

10+ Year Member



Hi,

Simple question here.

I'm trying to check whether an image location (pulled from a text file) exists, and if so display it. Not too difficult, but I have the problem that if the image doesn't exist, it displays a broken image.


if (!empty($data[$r][2])) {
echo "<span style=\"display: block;width:100%;\"><a href=\"loader.php?cid={$data[$r][0]}\"><img src=\
"/images/{$data[$r][2]}\"></a></span>\n";
} else {
echo "";
}

I need it to do nothing if there is no image link in the file.

Any thoughts?

dmmh

8:38 am on Jan 25, 2005 (gmt 0)

10+ Year Member



try this:

if (!empty($data[$r][2])) {?>
<span style="display: block;width:100%;"><a href="loader.php?cid=<? echo $data[$r][0];?>"><img src=
"/images/<? echo $data[$r][2];?>"></a></span><br/>
<?

mincklerstraat

9:32 am on Jan 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



have you tried:

if (!empty($data[$r][2]) && file_exists($data[$r][2])) {
echo "<span style=\"display: block;width:100%;\"><a href=\"loader.php?cid={$data[$r][0]}\"><img src=\
"/images/{$data[$r][2]}\"></a></span>\n";
} else {
echo "";
}

? This won't generate the link either if the image isn't there - if you want the link unconditionally you can set the whole img src string as a variable conditionally, on these same conditions, to either the img src or else the alternative, and just plop that variable inside the rest of the string (which then isn't conditional).