Jump to content

Broken images in php?


Mr Chris

Recommended Posts

Hi All,

 

Say I have a database record which holds an image name

 

<img src="http://www.gdgdgdgsks.co.uk/images/<?php echo $row['media_image']; ?>

 

The page will obviously be able to load the image, but say the image can't be found and it is broken ie the above outputs as:

 

<img src="http://www.gdgdgdgsks.co.uk/images/55.jpg

 

Which is a broken image.  Is there any in which I can use something in PHP which says if it's a broken image then output a default image (despite 55.jpg being the value saved in the database)

 

Thanks

 

Chris

 

Link to comment
https://forums.phpfreaks.com/topic/103534-broken-images-in-php/
Share on other sites

Hi Guys,

 

Thanks for the reply.  Here's how I have it:

 

  <?php
$path = "http://www.frededeeee.com/images/resize_image.php?image=http://www.frededeeee.com/images/properties";
$img = $prop['media_image_00'];

if(!file_exists($path.$img))
{
$img = "broken.jpg";
}

echo "<img src=\"$path/$img\" class=\"flb\" />";
?>

 

 

So

 

1) The value for 'media_image_00' in the database is outputted

2) The system then checks to see if the file exists

3) However, with the above if there is an image it still shows a broken.jpg image.

 

If I take out the if statement like so:

 

   <?php
$path = "http://www.frededeeee.com/images/resize_image.php?image=http://www.frededeeee.com/images/properties";
$img = $prop['media_image_00'];

if(!file_exists($path.$img))
{
$img = "broken.jpg";
}

echo "<img src=\"$path/$img\" class=\"flb\" />";
?>

 

The code works.  Now I think there is something wrong with the if statement:

 

if(!file_exists($path.$img))

 

 

Needs to be something like:

 

if(!file_exists($path/$img))

 

However if I use that it tries to use divide?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/103534-broken-images-in-php/#findComment-530203
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.