Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.