note 7207 deleted from mysql_db_query by danbeck

From: Date: Thu, 07 Sep 2000 15:29:43 +0000
Subject: note 7207 deleted from mysql_db_query by danbeck
Groups: php.notes 
Request: Send a blank email to php-notes+get-4365@lists.php.net to get a copy of this message
Here's how to process a form to upload an image directly to a MySQL database. It took me long time to get this right. It's much easier in Perl since you can pre-compile statments. Asumming we have a table: <pre> create table images ( image_id int unsigned, image longblob ); </pre> And an ENCTYPE="multipart/form-data" form with the image file in a file input called "image_file". <pre> $fhand = fopen($image_file,'r'); $image = fread( $fhand, filesize ($image_file)); fclose($fhand); // This is the important part: $tr = array("\"=>"\\","'"=>"\'"); $image=strtr($image,$tr); mysql_connect("localhost",$username,$password); $query = "INSERT INTO images (image_id,image) VALUES('$image_id','$image')"; $insertok = mysql_db_query($dbname, $query); </pre>

« previous php.notes (#4365) next »