jquery - Ajax Upload Image to Mysql Using "Mysqli-PHP" On server -


i trying insert image mysql database using php(mysqli) on server side , ajax on client when iam submitting image
showing error(s) follows

warning: file upload error - unable create temporary file in unknown on line 0

warning: file_get_contents(): filename cannot empty in x:\xxxx\xxxx\xxxx\xxxx\insert.php on line 3

ajax:

$("form[name='frmimage']").submit(function(e) {         var formdata = new formdata($(this)[0]);            $.ajax({             url: "insert.php",             type: "post",             data: formdata,             async: false,             success: function (msg) {                 alert(msg);                  $('#error').html(msg);         },         cache: false,         contenttype: false,         processdata: false     });      e.preventdefault(); });  

html:

<form name="frmimage" method="post" action=""     enctype="multipart/form-data" >              <input name="userimage" type="file" class="inputfile" />             <input type="submit" value="submit" class="btnsubmit" />      </form>      <div id="error"> 

php:

    $db = mysqli_connect("xxx","xxx","xxxx","xxx"); //keep db name     $image = addslashes(file_get_contents($_files['userimage']['tmp_name']));      $query = "insert images (id,image) values('','$image')";       $qry = mysqli_query($db, $query); 

sql query:

    create table `images` (       `id` int(100) not null auto_increment,       `image` longblob,       primary key (`id`)     ) engine=innodb default charset=utf8; 

you have miss match typo field name in php code: file input name userimage can image property using userimage

change

$_files['formdata']['tmp_name'] 

to

$_files['userimage']['tmp_name'] 

Comments