简体   繁体   English

fileupload 在 Twitter 引导程序中不起作用

[英]fileupload is not working in twitter bootstrap

I am using twitter bootstrap file upload, i want to store the image on databese and also i want to move in one folder,i spent lot of times, i can't get the file name value.我正在使用 twitter bootstrap 文件上传,我想将图像存储在数据库中,并且我想移动到一个文件夹中,我花了很多时间,我无法获取文件名值。 see here enter firstname and select one image after submit the form ,now i got first name value but i cant get photo upload value...请参阅此处输入名字并在提交表单后选择一张图片,现在我获得了名字值,但无法获得照片上传值...

<form class="form-horizontal form-bordered" method="POST" id="newUserForm" enctype="multipart/form-data">

                       <div class="form-group">
                           <label class="col-md-3 control-label">First Name<span class="star_mark">&nbsp;*</span></label>
                          <div class="col-sm-6">
                           <input type="text" class="form-control" id="fname" name="fname" value="" aria-required="true" required="" data-msg-required="Please enter your firstname" placeholder="Enter your firstname">

                          </div>
                      </div>
 <div class="form-group">
                      <label class="col-md-3 control-label">Photo Upload<span class="star_mark">&nbsp;*</span></label>
                      <div class="col-md-6">
                      <div class="fileupload fileupload-new" data-provides="fileupload">
                      <div class="input-append">
                      <div class="uneditable-input">
                      <i class="fa fa-file fileupload-exists"></i>
                      <span class="fileupload-preview"></span>
                      </div>
                      <span class="btn btn-default btn-file">
                      <span class="fileupload-exists">Change</span>
                      <span class="fileupload-new">Select file</span>
                       <input type="file" id="file" name="file">
                      </span>

                      <a href="#" class="btn btn-default fileupload-exists" data-dismiss="fileupload">Remove</a>
                      </div>
                      </div>
                      </div>
                      </div>

                      <div class="form-group">
                      <div class="col-sm-offset-3 col-sm-6">
                     <button class="btn btn-info btn-block" type="submit" id="user-submit">Submit</button>
                      </div>
                      </div>
                      </form>

<script type="text/javascript">
               $(document).ready(function(){
                $('#user-submit').click(function(event){
                    event.preventDefault();
                  if($('#newUserForm').valid()){
                    //console.log('success');
                     $.ajax({
                     type:'POST',
                     url :"php/register-newuser.php",
                     data: $('form#newUserForm').serialize(),
                     success: function(data) {
                        //var res=jQuery.parseJSON(data);// convert the json
                        console.log(data);

                     },
                     error:function(exception){
                     alert('Exeption:'+exception);
                    }
                  }); 

                     }
                else{

                  console.log('please select all fields');

                }
                });
              });
            </script>

register-newuser.php注册-newuser.php

$fstname=$_POST['fname'];// i got ans here
$filename  = basename($_FILES['file']['name']);
$newuser = array("fstName" => $fstname,'photoname' => $filename);
echo json_encode($newuser);
print_r($_FILES)//means nothing will happen, i didn't get any value like filename,size,extension....

To make an upload with AJAX you can use a jQUery plugin, for example this one .要使用 AJAX 进行上传,您可以使用 jQUEry 插件,例如这个插件。 Bootstrap has nothing to do with upload. Bootstrap 与上传无关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM