我使用bootstrap模式对话框上传文件。但是当提交表单时,$ _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">×</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>
我做错了什么?
答案 0 :(得分:3)
您需要添加表单的enctype。
<form method="post" id="noteForm" name="noteForm" action="documentAndNotesList.php" enctype="multipart/form-data">
答案 1 :(得分:0)
发送带文件的POST请求时,需要将编码类型更改为multipart。您可以使用<form>
标记的HTML属性执行此操作:
<form .. enctype="multipart/form-data">