|
Posted by eholz1 on 12/22/06 01:41
Hello Members,
I am setting up a photo website. I have decided to use PHP and MySQL.
I can load jpeg files into the table (medium blob, or even longtext)
and get the image(s) to display without a problem. I am using
chunk_split(data) and the base64_encode and base64_decode on the files.
I do a select from the database, and then echo the image (with
header(Content Type: image/jpeg)
and the decoded image displays fine. Yes, I have tried header(Content
Type: image/png), without
success.
My problem is png images. Is there something that I need to do
different in terms on reading/encodeing/decodeing the png image? I am
putting its "binary" data into the db table.
But when I do a select on a png image - it never displays in the
browser.
I am not using file/path names as references, but actually putting the
image in the db.
Here is a sample of code I use to insert the data into the table, and
to select the code from the table.
load image(s):
<?php
while ($file = readdir($dir_handle))
{
$filetyp = substr($file, -3);
if ($filetyp == 'png' OR $filetyp == 'jpg')
{
$handle = fopen($path . "/" . $file,'r');
$file_content = fread($handle,filesize($path . "/" . $file));
fclose($handle);
$encoded = chunk_split(base64_encode($file_content));
$sql = "INSERT INTO images SET sixfourdata='$encoded'";
mysql_query($sql);
}
}
?>
display images:
<?php
$result = @mysql_query("SELECT * FROM images WHERE id=" . $img . "");
if (!$result)
{
echo("Error performing query: " . mysql_error() . "");
exit();
}
while ( $row = mysql_fetch_array($result) )
{
$imgid = $row["id"];
$encodeddata = $row["sixfourdata"];
}
?>
<?php
//echo base64_decode($encodeddata);
echo $encodeddata;
?>
This process seems to always work with jpegs.
Thanks
ewholz
Navigation:
[Reply to this message]
|