Entry
How do I insert a user loaded image <input type=file> into a database table (MYSql or M/S SQL)
Feb 18th, 2008 19:31
dman, Cinley Rodick, Pavel Prishivalko, Peter Boritz, http://www.ttnr.org
Simple.
<?
$img_filename=$HTTP_POST_FILES['INPUT_FILE_NAME_HERE']['temp_name'];
$img_type=$HTTP_POST_FILES['INPUT_FILE_NAME_HERE']['type']
$fp = fopen($img_filename,'r');
$content = fread($fp,filesize($img_filename));
$content = addslashes($content);
$SQL = "insert into table_name (file_blob) values ('$content')";
?>
for extracting:
<?
....we got a row from DB, then:...
Header("Content/type: $img_type");
$content = $row['file_blob'];
$content=stripslashes($content);
echo($content);
die();
?>
I suggest using copy() and just copy you temporary file into webserver
dir and store file URL, not file itself - SQL server won't be so
overloaded...