2014-12-03 48 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">