Trouble with image upload {Ajax,php,Filereader} -


when upload image server return "empty".

what need change server or client work? want upload 1 image , dont have form etc html:

input id="imgupload" type="file" value="upload"

client side:

var reader = new filereader();                             function readurl(input) {                                 var filetypes = ['jpg', 'jpeg', 'png'];                                 var extension = input.files[0].name.split('.').pop().tolowercase(),                                     issuccess = filetypes.indexof(extension) > -1;                                 if (issuccess) {                                     reader.onload = function (e)                                     {                                         $('#img').attr('src', e.target.result);                                         $('#imguploadinput').hide();                                         $('#imguploadmenu').show();                                         $( "#imgsave" ).click(function() {                                             imagesave(e.target.result);                                         });                                     }                                     reader.readasdataurl(input.files[0]);                                 }                                 else{                                     imagedelete();                                     $('#error').html("file error!");                                 }                             }                             function imagesave(img){                                 //$('#imguploadmenu').hide();                                 $.ajax({                                     url: "system/profile/uploadimage.php",                                     type: "post",                                     data: {img:img},                                     success: function (data) {                                         $("#imgspinner1").hide();                                         $('#error').html(data);                                     },                                     beforesend: function() {                                         $("#imgspinner1").show();                                     }                                 });                             } 

server side:

$imageinfo = getimagesize($_files['img']['tmp_name']); if ($imageinfo['mime'] == ("image/png") || $imageinfo['mime'] == ("image/jpeg")     || $imageinfo['mime'] == ("image/gif") ||     $imageinfo['mime'] == ("image/bmp")) {     echo "ok";     } else {     if(empty($_files['img'])) echo "empty";     else echo "no empty"; } 


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -