简体   繁体   English

是什么导致$ _FILES ['file'] ['name']为空?

[英]What could cause $_FILES['file']['name'] to be empty?

I have a form which includes a file upload. 我有一个包含文件上传的表格。 Everything in the form seems to be working fine except that the $_FILES['file']['name'] turns up empty. 除了$_FILES['file']['name']为空外,该表格中的所有内容似乎都可以正常工作。

HTML 的HTML

<form ... >
<input class="file" type="file" name="file[]" />
<input class="file" type="file" name="file[]" />
<input class="file" type="file" name="file[]" />
</form>

PHP 的PHP

foreach ($_FILES['file']['name'] as $index => $file) {
    // Handle file upload
}

I get an error saying that the index $_FILES['file'] is not defined. 我收到一条错误消息,指出未定义索引$_FILES['file'] I've checked that file upload is enabled in PHP. 我检查了PHP是否启用了文件上传。 What else could be causing this to turn up empty? 还有什么可能导致这个结果变成空的?

Is the enctype right? 编码正确吗?

Try 尝试

<form action="upload_file.php" method="post" enctype="multipart/form-data">
   <input class="file" type="file" name="file[]" />
   <input class="file" type="file" name="file[]" />
   <input class="file" type="file" name="file[]" />
</form>

Without enctype no files will be uploaded, so the $_FILES array will be empty. 如果没有enctype,则不会上传任何文件,因此$_FILES数组为空。

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

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