Dec 15
This is what the form should look like.
<form action="uploader.php" enctype="multipart/form-data" method="post"> <input name="uploadfile" type="file" /> <input type="submit" value="Upload file" /> </form>
Then we create a table in the database to hold the file.
CREATE TABLE `cms`.`images` ( `image_id` int(10) unsigned NOT NULL auto_increment, `image` blob, `name` varchar(45) default NULL, `type` varchar(45) default NULL, `size` varchar(45) default NULL, `title` varchar(45) default NULL, PRIMARY KEY (`image_id`) ) ENGINE=MyISAM AUTO_INCREMENT=88 DEFAULT CHARSET=latin1;
Finally we have the uploader.php to insert the file into the database.
mysql_connect('localhost','cms_user','******') or die(mysql_error());
mysql_select_db('cms') or die(mysql_error());
$image_fp = fopen($_FILES['uploadfile']['tmp_name'], 'r');
$image = addslashes(fread($image_fp, $_FILES['uploadfile']['size']));
$name = $_FILES['uploadfile']['name'];
$type = $_FILES['uploadfile']['type'];
$size = $_FILES['uploadfile']['size'];
fclose($image_fp);
mysql_query("INSERT INTO images (image,name,type,size) VALUES ('$image','$name','$type','$size')") or die(mysql_error());
echo mysql_insert_id();
August 1st, 2009 at 4:58 pm
(CREATE TABLE `cms`.`image`) —-> CREATE TABLE `cms`.`images`
images is table not image
April 9th, 2012 at 7:43 am
Hi! I work for a long time in web, games, web development and if you need any help or have any questions shoot me a message: welcome at lezgro.com. Ask for Jim. Glad to help.