[英]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 保持为空,因此名称文件都没有写入数据库。 显然,目录“fatture”存在于服务器中的正确路径中......
您必须使用enctype="multipart/form-data"
<form name="item" method="post" enctype="multipart/form-data">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.