Easy CSS/php default image
In the process of developing an e commerce shopping cart, I had the need to make sure an image was displayed at all times… even if the link is broken for some reason. This easy solution will make sure that your large detail view image is loaded last… thus making your site appear that it loads faster (as per standards-compliant rules, while at the same time ensuring no [X] boxes pop up:
<?
$image = "./path/to/images/" . $itemnumber . ".jpg"; //generate path from already gathered info
if (!(file_exists($image))) // make sure file exists
$image = "./path/to/images/notfound.jpg"; // if file doesn't exist, revert to default
?>
<div id="detailView" style = "background-image: URL('<? echo $image; ?> ');"> //update style information real-time
Hopefully this should help somebody out who is trying to do something similar or develop their own e commerce solution. Saves on javascript code, minimized end-user page-load time, and uses minimal server resources.
| 2.9 |
Stumble it!
Post Info
This entry was posted on Monday, September 24th, 2007 and is filed under css, development, php. It has 57 viewsComments Feed. | Leave Comment | Leave Trackback.
Previous Post: CSS Tips and Tricks »
Next Post: Credit Card Processing »
Most viewed posts
























