PHP+HTML:文件未从表单加载


PHP+HTML: file not loaded from form

在我的表单中,用户可以选择上传文件。所以,这是表单中的对应字段。这是 HTML 代码:

<p>
 <label>Allega fattura</label>
 <span class="field">
 <input type="file" name="allegato_fattura" id="allegato_fattura" value="Sfoglia..." />
</span>

当单击提交按钮时,我们开始:

...
    define("DIR_FATTURE","fatture/");
    $fatturaFileName;
    $addedFattura = false;
    if (file_exists($_FILES['allegato_fattura']['tmp_name']) || is_uploaded_file($_FILES['allegato_fattura']['tmp_name'])) {
        $addedFattura = true;
        $fatturaFileName = $_FILES['allegato_fattura']['name'];
        if (file_exists(DIR_FATTURE.$_FILES['allegato_fattura']['name'])){
            $fatturaFileName=time()."_".$_FILES['allegato_fattura']['name'];
            $_FILES['allegato_fattura']['name']=$fatturaFileName;
        }
        move_uploaded_file($_FILES['allegato_fattura']['tmp_name'], DIR_FATTURE.$_FILES['allegato_fattura']['name']);
    }

这是行不通的。我为其他表单编写了相同的文件/脚本并且它们有效,我不知道为什么没有:没有加载文件并且变量 $fatturaFileNale保持 null,因此名称文件都不会写入数据库。显然,目录"fatture"存在于服务器中的正确路径中......

您必须使用enctype="multipart/form-data"

<form name="item" method="post" enctype="multipart/form-data">