PHP 个文件未使用 $_FILES 数组检测到

PHP files not detected using the $_FILES array

问题

$_FILES['file'] 数组已设置,但每当我尝试使用它时它都是空的。

我试过的

我所知道的事实

我的表单代码(HTML)和文件引擎代码(PHP)

<html>
<form method="POST" action="../php/post.php" enctype="multipart/form-data">
<h3>Title</h3>
<input type="hidden" name="case" value=1>
<input type="title" name="pname">
<h3>Message</h3>
<input type="message" name="pmsg">
<h3>Images</h3>
<input type="file" name="pimg[]" multiple>
<input class="submit" type="submit" value="Upload">
</form>
</html>

PHP

<?php
if (!empty($_FILES['file']['pimg'])){
$noFiles = 1;
echo "Files found...\n";
} else {
$noFiles = 0;
echo "Files not found...\n";
echo (!empty($_FILES['file']['pimg']));
echo $_FILES['file']['pimg'][0];
}
?>

输出

If判断数组为空,最后回显导致错误

你离得不远了。 $_FILES['file']['pimg'] 应该是 $_FILES['pimg'] 您还应该检查是否选择了某些内容。 $_FILES['pimg']['size'] 检查文件大小。如果为 0,则不选择任何内容

这种方式可行。

<?php

    if ($_FILES['pimg']['size'] != 0){
        $noFiles = 1;
        echo "Files found...\n";
        echo $_FILES['pimg']['name'][0];
    } else {
        $noFiles = 0;
        echo "Files not found...\n";
    
    /* This will always be empty placed here as no files have been found */
    //echo (!empty($_FILES['file']['pimg']));
    //echo $_FILES['file']['pimg']['name'][0];
    }

?>