File uploade with additional Data (Javascript, PHP) -




i want uploade file , send additional data (an array) php script.

here html , javascript code:

<input type="file" name="fileinput" id="fileinput"> <button class="btn btn-primary" id="btnupload">upload</button> <script>  $('#btnupload').click(function(){  var formdata = new formdata();  formdata.append("macstochangeimage", selectedmacs.tostring()); //selectedmacs array want send  formdata.append("userfile", $('#fileinput').files[0]);  $.ajax({   url: "changeimagesfunction.php",   type:'post',   data: formdata,   processdata: false,   cententtype: false,   success: function(data)   {       alert('success' + data);   },   error:function(response){     alert(json.stringify(response));   }  }); });  </script> 

and here ist php code:

if(!empty($_files)) {  $target_dir = "img/epd_uploads/";  $temporaryfile = $_files['userfile']['tmp_name'];  $targetfile =  $target_dir . $_files['userfile']['name'];  if(!move_uploaded_file($temporaryfile,$targetfile))  {    echo "error occurred while uploading file server!";  }else{     if (isset($_post['macstochangeimage'])){     //name of uploaded file     $changeimagetophp = $_files['userfile']['name'];     //get array     $macstochangeimagestr = $_post['macstochangeimage'];     $macstochangeimagephp = explode(",",$macstochangeimagestr);     }   } } 

i think html , javascript part fine far. uncertain how handle php part. doing worng/missing?

are there other ways achieve im plannig do?

thank in advance





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -