Php 未将文件发布到$\u files超级全局数组

Php 未将文件发布到$\u files超级全局数组,php,html,Php,Html,我有一个项目的文件上传部分的问题。我已经用输入创建了表单,但是当我尝试“上载”文件时,它不会发布到$\u FILES数组中。代码贴在下面。我已经在from标记中声明了一个enctype,但是文件仍然没有被发布到数组中,它只显示array() 这是我的表格代码: <?php require("includes/application_top.php"); $pageTitle = "Add A Product"; require("incl

我有一个项目的文件上传部分的问题。我已经用输入创建了表单,但是当我尝试“上载”文件时,它不会发布到$\u FILES数组中。代码贴在下面。我已经在from标记中声明了一个
enctype
,但是文件仍然没有被发布到数组中,它只显示
array()

这是我的表格代码:

<?php

require("includes/application_top.php");
$pageTitle = "Add A Product";
require("includes/header.php");
print_r($_FILES);

?>
<div class="container-fluid py-4">

<div class="row ">
    <div class="col">
        <form method="POST" action="s.php" enctype="multipart/form-data">
            <!-- Product Name input -->
            <div class="form-outline">
                <input type="text" id="ProductName" class="form-control" />
                <label class="form-label" for="ProductName"> Product Name</label>
            </div>
    </div>
    <div class="col">
        <!-- Product Description input -->
        <div class="form-outline">
            <input type="text" id="ProductDesc" class="form-control" />
            <label class="form-label" for="ProductDesc">Product Description</label>
        </div>
    </div>
</div>

<hr />

<div class="row">
    <div class="col">
        <!-- Product Price input -->
        <div class="form-outline">
            <input type="number" min="0.00" max="10000.00" step="0.01" id="ProductPrice" class="form-control" />
            <label class="form-label" for="ProductPrice">Product Price </label>
        </div>
    </div>
    <div class="col">
        <!-- Img Upload input -->
        <div class="form-outline input-group mb-3 ">
            <input type="file" id="ImageUpload" class="form-control" />

            <input type="submit" value="Upload" />
        </div>
    </div>
</div>
</form>
</div>
<?php
require("includes/footer.php")
?>

品名
产品说明

产品价格
任何表单字段必须具有
名称
属性,以便在提交表单后填充PHP的
$\u GET
$\u POST
$\u文件
超全局

$\u GET
$\u POST
取决于表单方法,而
$\u FILES
特定于文件上载(仅限HTTPPOST方法)

然后,您的文件输入应如下所示:


给定我写的
image\u upload
名称,您应该能够使用
$\u FILES['image\u upload]
获取文件信息


阅读文档中的文件上载:。

您必须为字段提供名称属性,$\u POST和$\u文件都使用名称属性,而不是ID。ID主要用于使用javascript处理字段时,例如使用ajax请求提交表单时

在您的情况下,您需要名称:

<input type="file" id="ImageUpload" class="form-control" />

将成为

<input type="file" name="ImageUpload" class="form-control" />


其他输入字段也是如此,您需要一个name属性,然后才能在$\u POST中看到。

仔细检查
表单
元素的开始和结束标记是否在您希望的位置。