Php Image From Database Using PEAR::DB
Join the DZone community and get the full member experience.
Join For FreeThis fetches an image from a MySQL database (I know, a database may not be the best place to keep images). The image is sent to the web client as an image/jpeg.
getMessage());
}
if (isset($_GET['id'])) {
header('Content-Type: image/jpeg');
$id = $_GET['id'];
$sql = "select image_data from images where id = ?";
$result =& $db->query($sql, $id);
if (PEAR::isError($result)) {
die($result->getMessage());
} else {
if ($result->fetchInto($row)) {
echo $row[0];
}
}
} else {
echo file_get_contents('broken.png');
}
?>
Database
Opinions expressed by DZone contributors are their own.
Comments