| |||||||||||
| |||||||||||
Inserting an image as a blob in PHP Posted by andrewtayloruk (andrewtayloruk), 23 March 2007 Hi Graham and everyone else on the forums. I was wondering if somebody on here could help...I've made a form upload script that inserts the data from the forms into an sql database. The thing i'm stuck on is getting the image from the final input box and putting it into the database as a blob. *** Code below *** <?php if (isset($_POST['submitted'])) { $name = trim(strip_tags($_POST['name'])); $address = trim(strip_tags($_POST['address'])); $postcode = trim(strip_tags($_POST['postcode'])); $telephone = trim(strip_tags($_POST['telephone'])); $email = trim(strip_tags($_POST['email'])); $picture = trim(strip_tags($_POST['picture'])); $dbid = mysql_connect ('localhost', 'root'); mysql_select_db('addresses',$dbid) or die ("Cannot find database"); $query = "INSERT INTO `book` (`aid`, `name`, `address`, `postcode`, `telephone`, `email`, `picture`) VALUES ('', '$name', '$address', '$postcode', $telephone, '$email' , '$picture')"; $result = mysql_query($query,$dbid) or die("INSERT error:".mysql_error()); echo 'Row inserted'; exit; } ?> <html> <head> <title>Data submission - db version</title> </head> <body> <form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Name: <input name="name" /><br /> Address: <input name="address" /><br /> Postcode: <input name="postcode" /><br /> Telno: <input name="telephone" /><br /> Email: <input name="email" /><br /> Picture:<br><input type="file" name="picture" size"80" /><br /> <br><input type="submit" name="submitted" value="Submit" ></form><br> </body> </html> Posted by admin (Graham Ellis), 24 March 2007 You need to look at move_uploaded_file to move the image you've uploaded to somewhere you can read it, then read it into a string. And don't strip_tags out of the picture in any way as any binary data that looks like a tag would get damaged ![]() Here's an image upload script that I wrote showing the bare bones ... Code:
This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |