// may want to assure yourself this is actually an image, with GD or Imagick
$img_data = file_get_contents($_FILES[...]);
//the DB field data type should be BLOB.
UPDATE tblname SET imagefield = '$img_data' WHERE something = ...
// or INSERT INTO ... of course
<img src="http://example.com/image.php?id=4"/>
if (!isset($_GET['id']) || ($id = (int) $_GET['id']) == 0) {
header('HTTP/1.1 400 Bad request'); // alternatively 404
exit;
}
$result = $db->query('SQL to retrieve image here');
if (!$result) {
header('HTTP/1.1 404 Not Found'); // alternatively 404
exit;
}
# send header with content-type: image/subtype, such as jpeg, png, gif...
# echo image_data