Inserting Image as Blob in MySql DB

From: Date: Mon, 26 Mar 2001 04:41:09 +0000
Subject: Inserting Image as Blob in MySql DB
Groups: php.db 
Request: Send a blank email to php-db+get-7790@lists.php.net to get a copy of this message
Hi, Does anyone know the proper method for inserting an image(*.jpg or *.gif) into a MySql database blob field? I am recieving the file via an html form with the usual enctype for this and <input type=file> parameters. I can save it as just a regular file and then display it fine on the page, but no way can I update the database with this...and have tried everything imaginable...surely this is done everyday and is quite simple. code snippet below - and yes, I am a php beginner...ASP by day and trying to learn PHP by night.. ------------------------- $photo = fopen($txtImage, "r"); $filecontents = fread($photo, filesize($txtImage)); echo "<br>"; echo "<img src='$photo'>"; $anotherfile = fopen("/www/htdocs/Survey/$thisfile", "a+"); fputs($anotherfile, $filecontents); //fclose($anotherfile); echo "<br>"; echo "<img src='$anotherfile'>"; echo "<br>"; echo $photo; echo "<br><br><center>"; echo "<img src='$thisfile'>"; $crapola = "101010101"; echo "<br><br><center>"; $connection = mysql_connect("mysql.iticom.net","fractalv","fw348vnj") or die ("crap!"); $db = mysql_select_db("fractalv", $connection) or die ("db"); $sql = "INSERT INTO Images (Image, ImageType,ImageGallery,ImageLink,ThumbnailLink) VALUES ('$filecontents','$txtImageType', '$txtImageGallery', '$txtImageLink', '$txtThumbnailLink')"; $sql_result = mysql_query($sql,$connection) or die ("could not insert into DB"); mysql_close($connection); ---------------------ect. thanks in advance for absolutley any ideas! Phil J. .

« previous php.db (#7790) next »