Hello everyone. I want my script to check to see if a file exists then display it if it does, otherwise show some text like "no picture available"
Here is the code I am using:
$filename = 'equipment/pictures/$Stock_ID.pdf';
if (file_exists($filename)) {
echo "<a href='http://www.landmarkmn.com/equipment/pictures/$Stock_ID.pdf' />Download Spec Sheet</a>";
}
$filename = 'equipment/pictures/$Stock_ID.jpg';
if (file_exists($filename)) {
echo "Photo: <br><br><img src='http://www.landmarkmn.com/equipment/pictures/$Stock_ID.jpg' />";
}
The website url is: http://www.landmarkmn.com/equipment.php?act=view&id=85
Basically, I just wanna show a link to a pdf file if its there and show the picture if its there.
Now, I have this embedded into a page full of code, here is that page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Landmark Equipment Database: New, Used and damanged equipment for restaurants, foodservice, kitchens, coffee shops</title>
<meta name="description" content="Restaurant equipment and design serving local and nationwide Restaurateurs. We provide planning for all phases of design, equipment for all foodservices systems and installation of the equipment.">
<meta name="keywords" content="Restaurant, Equipment, new, used, damaged, Design, Planning, Installation, Interior Design, Consultant, Kitchen, Foodservice, Servery, College, Corporate, Commercial, Themed, Hotel, Upscale, Bar, Night Club, Retail, Coffee Shop, Grill, Diner, Casino, Water Park, Resort, Hospitality, Fast Food, University, Cooking Line, Cooler, Freezer, Counters, Oven, Griddle, Range, Fryer, Prep Table, Hot Well, Cold Well">
<script language="javascript">AC_FL_RunContent = 0;</script>
<script src="AC_RunActiveContent.js" language="javascript"></script>
<script language=javascript>
function openUp(){
self.resizeTo(970,800);
self.moveTo(0,0);
}
</script>
</head>
<body onLoad="javascript:openUp()">
<?php
$host = "localhost"; //your sql host, usually 'localhost'
$user = "_"; //username to connect to database
$pass = ""; //password to connect to database
$db = "_"; //the name of the database
mysql_connect($host,$user,$pass) or die("ERROR:".mysql_error());
mysql_select_db($db) or die("ERROR DB:".mysql_error());
$max = 15; //amount of articles per page. change to what to want
$p = $_GET['p'];
if(empty($p))
{
$p = 1;
}
$limits = ($p - 1) * $max;
//view the news article!
if(isset($_GET['act']) && $_GET['act'] == "view")
{
$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM equipment WHERE id = '$id'");
while($r = mysql_fetch_array($sql))
{
$Stock_ID = $r['Stock_ID'];
$Mfr = $r['Mfr'];
$Model = $r['Model'];
$Description = $r['Description'];
$Condition = $r['Condition'];
echo "<p align=center><a href=http://www.landmarkmn.com border=0><img src=images/logo.jpg alt=Landmark width=430 height=115></a>
<font color=#990000 face=Arial, Helvetica, sans-serif><strong><br>
Contact us at 612-673-9309 with any questions about this piece of equipment</strong></font></p><div align=center><font face=Arial, Helvetica, sans-serif><p>Stock ID: $Stock_ID</p><p>Manufacturer: $Mfr</p><p>Model: $Model</p><p>Description: $Description</p><p>Condition: $Condition</p>";
$filename = 'equipment/pictures/$Stock_ID.pdf';
if (file_exists($filename)) {
echo "<a href='http://www.landmarkmn.com/equipment/pictures/$Stock_ID.pdf' />Download Spec Sheet</a>";
}
$filename = 'equipment/pictures/$Stock_ID.jpg';
if (file_exists($filename)) {
echo "Photo: <br><br><img src='http://www.landmarkmn.com/equipment/pictures/$Stock_ID.jpg' />";
}
}
}else{
//view all the news articles in rows
$sql = mysql_query("SELECT * FROM equipment LIMIT ".$limits.",$max") or die(mysql_error());
//the total rows in the table
$totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM equipment"),0);
//the total number of pages (calculated result), math stuff...
$totalpages = ceil($totalres / $max);
//the table
echo "<table align=center><tr><td align=center><a href=http://www.landmarkmn.com border=0><img src=images/logo.jpg alt=Landmark width=430 height=115></a><font color=#990000 face=Arial, Helvetica, sans-serif><strong><br>
Contact us at 612-673-9309 with any questions about equipment listed below</strong></font><br><br><font size=2px color=#990000 face=Arial, Helvetica, sans-serif>Equipment is sorted by manufacturer</font><br></td></tr><tr><td align=center><table align=center width=100% border=0 cellpadding=5 cellspacing=1 bgcolor=#000000><tr><td bgcolor=#FFFFFF align=left><font size=4px face=Arial, Helvetica, sans-serif>Stock ID</font></td><td bgcolor=#FFFFFF align=left><font size=4px face=Arial, Helvetica, sans-serif>Mfr</font></td><td bgcolor=#FFFFFF align=left><font size=4px face=Arial, Helvetica, sans-serif>Model</font></td><td bgcolor=#FFFFFF align=left><font size=4px face=Arial, Helvetica, sans-serif>Description</font></td><td bgcolor=#FFFFFF align=left><font size=4px face=Arial, Helvetica, sans-serif>Condition</font></td></tr><tr>";
while($r = mysql_fetch_array($sql))
{
$id = $r['id'];
$Stock_ID = $r['Stock_ID'];
$Mfr = $r['Mfr'];
$Model = $r['Model'];
$Description = $r['Description'];
$Condition = $r['Condition'];
echo "<tr><td bgcolor=#FFFFFF align=left><font size=3px face=Arial, Helvetica, sans-serif><a href='equipment.php?act=view&id=$id'>$Stock_ID</font></a></td><td bgcolor=#FFFFFF align=left><font size=3px face=Arial, Helvetica, sans-serif>$Mfr</font></td><td bgcolor=#FFFFFF align=left><font size=3px face=Arial, Helvetica, sans-serif>$Model</font></td><td bgcolor=#FFFFFF align=left><font size=3px face=Arial, Helvetica, sans-serif>$Description</font></td><td bgcolor=#FFFFFF align=left><font size=3px face=Arial, Helvetica, sans-serif>$Condition</font></td></tr>";
}
//close up the table
echo "</tr></table></td></tr></table><table align=center cellpadding=8 cellspacing=1><tr>";
for($i = 1; $i <= $totalpages; $i++){
//this is the pagination link
echo "<td><font size=3px face=Arial, Helvetica, sans-serif><a href='equipment.php?p=$i'>Page $i</a></font></td>";
}
}
echo "</tr></table>";
?>
</body>
</html>
Any ideas why the code will not work? I can get it to display text...but not an image or link.
Thanks in advance!