Faqts : Computers : Programming : Shopping For You : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

87 of 151 people (58%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How do I insert a user loaded image <input type=file> into a database table (MYSql or M/S SQL)

Jan 24th, 2009 09:08
Brad Kint, healthy man, 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...
http://forsakringguide.blogspot.com
http://ghiddeasigurare.blogspot.com
http://guidedelassurance.blogspot.com
http://reiseneuropa1.blogspot.com
http://europadecalatorie.blogspot.com
http://reizeneuropa1.blogspot.com
http://rejsereuropa.blogspot.com
http://consiglibellezza1.blogspot.com
http://www.healthdothealth.com
http://www.healthxhealth.com
http://www.mesotheliomainmesothelioma.com
http://www.healthfirewall.com
http://www.flathealth.com
http://www.healthbodyguard.com