What you need to do, is follow the instructions for putting it in the directory, but once the file is uploaded in to it\'s temporary location, use the function fopen() to open the file, read the contents of the file in to a variable, use the functions chunk_split(base64_encode()); to encode the file properly, input the variable into MySQL. when you\'re ready to take it back out and display it, set the encoded data to a variable and use this the IMG SRC tag setting SRC=\"data:$filetype;base64,$encoded_data\"
<?
$result=mysql_query("select data,filetype from images where id=1");
$data=mysql_fetch_row($result);
$encoded_data=$data[0];
$filetype=$data[1];
echo "<img src="data:$filetype;base64,$encoded_data">";
?>
I\'ve noticed however that MSIE 6 has a problems with it, but NS7 works, if any one knows if IE can do the Inline images, please inform us.
The code for the first part is something like this...
<?php
$submit=$_POST["submit"];
if ($submit!="Submit") {
echo "<table align=center>";
echo "<center><form ENCTYPE="multipart/form-data" method=post action=album.php?mode=upload>";
echo "<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="0">";
echo "<TR><TD>File: <TD><input name="file[]" type=file>";
echo "<input type=submit name=submit value="Submit"></form>";
} else {
$file=$_FILES["file"][\'tmp_name\'][0];
$file_name=$_FILES["file"][\'name\'][0];
$file_size=$_FILES["file"][\'size\'][0];
$file_type=$_FILES["file"][\'type\'][0];
$handle = fopen("$file",\'rb\');
$file_content = fread($handle,$file_size);
fclose($handle);
$encoded_data= chunk_split(base64_encode($file_content));
mysql_query(insert into images set data=\'$encoded_data\',filetype=\'$file_type\',name=\'$file_name\',size=\'$file_size\') or die(mysql_error());
header ("Location: index.php");
}
?>
Sorry if I\'ve mad any mistakes in there, I\'m pulling it from the back of my mind. I hope it helps.
-Nevets