webForumDet fria alternativet

Beräkna sizen av BLOB fält

PHP

1 svar · 439 visningar · startad av Hampan90

Medlem sedan feb. 2007137 inlägg
Frågan#1

Hallå. har denna kod:

// get the image from the db
$sql = "SELECT bild, OCTET_LENGTH(bild) FROM produkt WHERE id=$_GET[id]";
// the result of the query
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());

if($result['OCTET_LENGTH(bild)'] == 0)
{
header("Content-type: image/jpeg");
echo file_get_contents("Images/images/produkter/ingen_bild.jpg");

}
else{
// set the header for the image
 header("Content-type: image/jpeg");
echo mysql_result($result, 0);
}

Så, nu har jag ändrat koden lite, men jag fått att IF satsen alltid blir true nu, alltså.. den fattar inte när det finns en bild.

Detta är ganska akut, har deadlie idag

// Hampus

Medlem sedan mars 20007 896 inlägg
#2
// get the image from the db
$sql = "SELECT bild, OCTET_LENGTH(bild) AS imagesize FROM produkt WHERE id=$_GET[id]";
// the result of the query
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
$row = mysql_fetch_array($result);

if($row['imagesize'] == 0)
{
header("Content-type: image/jpeg");
echo file_get_contents("Images/images/produkter/ingen_bild.jpg");

}
else{
// set the header for the image
header("Content-type: image/jpeg");
echo $row['bild'];
}
247 ms totalt · 4 externa anrop · v20260731065814-full.86ec41c2
115 ms — deklarationer (db)
0 ms — hämta statistik (cache)
127 ms — hämta tråd, inlägg och bilagor (db)
118 ms — ändringar (db)