javascript - Cannot upload file using bootstrapValidator Ajax -


i have problem upload file. using bootstrapvalidator ajaxsubmit form validation. insert data in database work well, not file uploaded. using code :

html:

<form action="target.php" method="post" enctype="multipart/form-data" name="myform" id="myform">                <div class="form-group">               <label class="control-label col-sm-3">username</label>               <div class="col-sm-8">                 <input type="text" class="form-control" id="username" name="username" >               </div>             </div>                 <div class="form-group">               <label class="control-label col-sm-3">description</label>               <div class="col-sm-8">                 <input type="text" class="form-control" id="description" name="description">               </div>             </div>            <div class="form-group">             <label class="control-label col-sm-6">1. file a</label>             <div class="col-sm-5">                   <input type="file" name="firstfile" accept="application/pdf"/>                         <span class="help-block">(format : .pdf)</span>             </div>           </div>           <div class="form-group">             <label class="control-label col-sm-6">2. file b</label>             <div class="col-sm-5">             <input type="file" name="secondfile" accept="application/pdf">             <span class="help-block">(format : .pdf)</span>             </div>           </div>           <div class="form-group">             <label class="control-label col-sm-6">3. file c</label>             <div class="col-sm-5">                <input type="file" name="thirdfile" accept="application/pdf">             <span class="help-block">(format : .pdf)</span>             </div>           </div>           <div class="form-group">             <label class="control-label col-sm-6">4. file d</label>             <div class="col-sm-5">               <input type="file" name="fourthfile" accept="image/jpeg">             <span class="help-block">(format : .jpg/jpeg)</span>               </div>           </div>   <button type="submit" class="btn btn-primary" name="submit" id="submit">submit</button> 

javascript :

$(document).ready(function() { $('#myform').bootstrapvalidator({     message: 'this value not valid',     feedbackicons: {         valid: 'glyphicon glyphicon-ok',         invalid: 'glyphicon glyphicon-remove',         validating: 'glyphicon glyphicon-refresh'     },     fields: {         username: {             validators: {                 notempty: {                     message: 'not empty'                 }             }         },         description: {             validators: {                 notempty: {                     message: 'not empty'                 }             }         },         firstfile: {             validators: {                 file: {                     extension: 'pdf',                     type: 'application/pdf',                     minsize: 500*500,                     message: 'please choose pdf file size more 1m.'                 }             }         },         secondfile: {             validators: {                 file: {                     extension: 'pdf',                     type: 'application/pdf',                     minsize: 500*500,                     message: 'please choose pdf file size more 1m.'                 }             }         },         thirdfile: {             validators: {                 file: {                     extension: 'pdf',                     type: 'application/pdf',                     minsize: 500*500,                     message: 'please choose pdf file size more 1m.'                 }             }         },         fourthfile: {             validators: {                 file: {                     extension: 'jpg',                     type: 'image/jpeg',                     minsize: 50*50,                     message: 'please choose pdf file size more 1m.'                 }             }         }     }     }) .on('success.form.bv', function(e) {         // prevent submit form         e.preventdefault();          var $form     = $(e.target),             validator = $form.data('bootstrapvalidator');         $.post($form.attr('action'), $form.serialize(), function(result) {             console.log(result);         }, 'json');         $form.find('.alert').html('thanks signing up. can sign in ' + validator.getfieldelements('namapendaftar').val()).show();             $form             .bootstrapvalidator('disablesubmitbuttons', false)  // enable submit buttons             .bootstrapvalidator('resetform', true);             // reset form }); 

and target.php :

$link = mysqli_connect("localhost", "root", "", "testing"); if($link === false){     die("error: not connect. " . mysqli_connect_error()); }      $username = mysqli_real_escape_string($link, $_post['username']); $description = mysqli_real_escape_string($link, $_post['description']); $firstfile = mysqli_real_escape_string($link, $_post['firstfile']);  $secondfile = mysqli_real_escape_string($link, $_post['secondfile']);  $thirdfile = mysqli_real_escape_string($link, $_post['thirdfile']);  $fourthfile = mysqli_real_escape_string($link, $_post['fourthfile']);   $dir = $username; $target_dir = "file/$dir/"; if( is_dir($target_dir) === false )     {         mkdir($target_dir);     }  $firstfile = $target_dir . basename($_files["firstfile"]["name"]); $secondfile = $target_dir . basename($_files["secondfile"]["name"]); $thirdfile = $target_dir . basename($_files["thirdfile"]["name"]); $fourthfile = $target_dir . basename($_files["fourthfile"]["name"]);  $uploadok = 1; $firstfiletype = pathinfo($firstfile,pathinfo_extension); $secondfiletype = pathinfo($secondfile,pathinfo_extension); $thirdfiletype = pathinfo($thirdfile,pathinfo_extension); $fourthfiletype = pathinfo($fourthfile,pathinfo_extension);  move_uploaded_file($_files["firstfile"]["tmp_name"], $firstfile); move_uploaded_file($_files["secondfile"]["tmp_name"], $secondfile); move_uploaded_file($_files["thirdfile"]["tmp_name"], $thirdfile); move_uploaded_file($_files["fourthfile"]["tmp_name"], $fourthfile);  $sql = "insert test (username, description, firstfile, secondfile, thirdfile, fourthfile) values ('$username', '$description', '$firstfile', '$secondfile', 'thirdfile', '$fourthfile')";  if(mysqli_query($link, $sql)){     header("location: index.php?success"); } else{     echo "error: not able execute $sql. " . mysqli_error($link); } mysqli_close($link); 

is there can me ?

  • check memory_limit, upload_max_filesize, post_max_size in php.ini file
  • check permission of directory files should uploaded.
  • hope may solve problem.

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -