Jump to content

if statement with images


gazalec

Recommended Posts

i was wondering if it is possible to have an if statement with image for example

 

<?

if("<img src='directory/pic.jpg'> == '' "){
echo
"<img src='directory/alternativepic.jpg'>";
}else{
echo
"<img src='directory/pic.jpg'>";
}

?>

 

if this isn't possible then does anyone know how to get this effect

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/37312-if-statement-with-images/
Share on other sites

ok sorry i'm in the process of making a website with ALOT of products so instead of all the products having a separate page i'm making one php page that will call the products ID from a database and display everything needed so instead of having 500 pages i have 1, the only problem is some of the images dont have an image and i just wanted it so that if there is no image it displays an alternative image sayin, No image available or something along those lines and i was just wondering if it would be possible for PHP to look in the folder and if it doesn't find an image it displays the alternative.

 

thanks

I guess you d like to check if image exists?

 

Or .. if image is not blank file?

 

If you'd like to check if image exists try this:

<?php

if (file_exsists('dir/img.jpeg')

{

echo "<img src='dir/img.jpeg'>";

}

?>

 

If you'd like to check if image is not a blank file than the code would be:

<?

$minsize = "1000000"; //in bytes

$filepath = "dir/img.jpeg";

 

if ($minsize < filesize($filename))

{

echo "<img src='dir/img.jpeg'>";

}

?>

 

Hope this is it!

 

 

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.