Certainly possible - and probably a good idea (data is only about 33% larger than original). After upload, simply load the JPEG image into a string; encode with base64_encode() and then insert into the your image field (as BLOB) in the database (don't forget to use mysql_escape_string() of course).
On the way out; your image serving script simply needs to send the correct Content-Type header; and then use base64_decode and then print the output... e.g.
image.php
<?php header("Content-Type: image/jpeg"); // db connection code here $result = mysql_query("SELECT jpeg_base64 FROM table WHERE id='".mysql_escape_string($_GET["id"]."'"); $row = mysql_fetch_assoc($result); $jpeg_raw = base64_decode($row["jpeg_base64"]); print $jpeg_raw; exit(); ?>
Hi Russell, Certainly
Hi Russell,
Certainly possible - and probably a good idea (data is only about 33% larger than original). After upload, simply load the JPEG image into a string; encode with base64_encode() and then insert into the your image field (as BLOB) in the database (don't forget to use mysql_escape_string() of course).
On the way out; your image serving script simply needs to send the correct Content-Type header; and then use base64_decode and then print the output... e.g.
image.php
<?phpheader("Content-Type: image/jpeg");
// db connection code here
$result = mysql_query("SELECT jpeg_base64 FROM table WHERE id='".mysql_escape_string($_GET["id"]."'");
$row = mysql_fetch_assoc($result);
$jpeg_raw = base64_decode($row["jpeg_base64"]);
print $jpeg_raw;
exit();
?>
Cheers,
David.