2014-12-03 44 views
1

我正在使用引导模式对话框上传文件。但是,当提交表单时,$ _FILES数组不包含任何文件。文件上传不会在引导模式下返回文件

这里是我的PHP代码:

if (isset($_POST['saveButton'])) 
{ 
    $file = $_FILES['fileField']['name']; 
} 

,这里是我的html代码:

<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal"> 
     Launch demo modal 
    </button> 

    <!-- Modal --> 
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
     <div class="modal-dialog"> 
      <div class="modal-content"> 
       <form method="post" id="noteForm" name="noteForm" action="documentAndNotesList.php"> 
        <div class="modal-header"> 
         <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> 
         <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
        </div> 
        <div class="modal-body"> 
         <input type="file" id="fileField" name="fileField" /> 
        </div> 
        <div class="modal-footer"> 
         <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> 
         <button type="submit" id="saveButton" name="saveButton" class="btn btn-primary">Save changes</button> 
        </div> 
       </form> 
      </div> 
     </div> 
    </div> 

我在做什么错?

回答

3

您需要添加表单的enctype。

<form method="post" id="noteForm" name="noteForm" action="documentAndNotesList.php" enctype="multipart/form-data"> 

Reference:

+0

非常感谢您!这对我有效。 – Yaza 2014-12-03 11:10:06

+0

@Yaza,请你选择我的答案作为解决方案吗? – Pupil 2014-12-03 11:14:17

0

当文件发送POST请求您需要更改编码类型为多部分。你为<form>标签做到这一点与HTML属性:

<form .. enctype="multipart/form-data">