Ik heb een applicatie met verschillende tabellen, die elk een eigen icon hebben.
Dat icon verschijnt dan in het menu. Althans, zo zou het moeten :)
Eerst de tabelstructuur:
CREATE TABLE `_tables` (
`id` int(11) NOT NULL auto_increment,
`name` tinytext NOT NULL,
`caption` tinytext NOT NULL,
`level` tinyint(2) NOT NULL default '3',
`image` blob,
`is_list` tinyint(1) NOT NULL default '1',
`is_view` tinyint(1) NOT NULL default '1',
`is_edit` tinyint(1) NOT NULL default '1',
`is_add` tinyint(1) NOT NULL default '1',
`is_delete` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
Dan de "image.php" die de afhandeling doet:
<?php
include ("inc.db.php");
$x_data = $_GET["x"];
// $x_data: parameter string 'tabelnaam|id|veldnaam'
if (!($x_data == "") and !(is_null($x_data))) {
$a = explode('|', $x_data);
$x_tbl = $a[0];
$x_id = $a[1];
$x_fld = $a[2];
// nieuw object van database class
$db = new dbSet;
// sql: "select <field> from <table> where id = <id>"
$db->dbSelect($x_fld, $x_tbl, 'id='.$x_id);
if ($db->totalRecs() > 0) {
// mysql_fetch_array()
$row = $db->dbRecord();
header("Content-type: image/gif");
echo $row[0];
}
$db->dbClose();
}
?>
De betreffende class uit de css:
img.imgPhoto {border:2px solid #666666;}
En tot slot de aanroep:
<?php
session_start();
ob_start();
// ############################################### header
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Cache-Control: private");
header("Pragma: no-cache");
include_once("inc.db.php");
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ';
echo '"http://www.w3.org/TR/html4/loose.dtd">';
echo '<html><head><title>[de titel]</title>';
echo '<link href="_global.css" rel="stylesheet" type="text/css" media="all" />';
echo '<link rel="icon" href="favicon.ico" type="image/x-icon" />';
echo '</head><body>'."\n\n";
// ############################################### body
// hard coded voor de test
echo '<img src="image.php?x=_tables|1|image" ';
echo 'width="24" ';
echo 'height="24" ';
echo 'border="0" ';
echo 'alt="alt!" ';
echo 'title="alt!" ';
echo 'class="imgPhoto" ';
echo '/>'."\n\n\n\n";
// ############################################### footer
echo '</body>';
echo '</html>';
Bronnen op het internet hebben een vergelijkbare structuur.
Zowel FF als IE laten wel de alt-tag zien, maar geen plaatje.
Als ik de blob als tekst ophaal, dan krijg ik deze WEL te zien.
Dit zegt me, dat hij 'm wel ophaalt uit de database en dat "image.php" dus klopt.
Wat gaat hier nu zo fout?
Roland