我正在使用一个简单的表单上传5个文件:
<form enctype="multipart/form-data" action="openaccount.php" method="post">
<h4>Proof of Identity of Account Operator 1</h4>
<p>Government issued Photo ID to verify identity:
<br/><input name="tidentity_proof" type="file" />
<p>Documentation to verify permanent residential address:
<br/><input name="taddress_proof" type="file" />
<h4>Proof of Identity of Account Operator 2 (if any)</h4>
<p>Government issued Photo ID to verify identity:
<br/><input name="tidentity_proof2" type="file" />
<p>Documentation to verify permanent residential address:
<br/><input name="taddress_proof2" type="file" />
<h4>Signed Fund Agreement</h4>
<p>Choose a file to upload:
<br/><input name="tagreement" type="file" />
<input type="submit" name="submit" value="Submit" />
</form>
由于这五个文件中的每一个都是强制性的,我会在提交表单时检查是否已经上传了所有文件:
if($_FILES['tidentity_proof']['name']=="" || $_FILES['tidentity_proof2']['name']=="" || $_FILES['taddress_proof']['name']=="" || $_FILES['taddress_proof2']['name']=="" || $_FILES['tagreement']['name']==""){
$_SESSION['message'].="You must upload files as identity proof.";
}
如果我为所有5个字段选择文件,前4个工作正常,但第5个工作没有。因此,如果我echo $_FILES['tagreement']['name'];
我得到一个空字符串,如果我对所有其他字符串执行相同的操作,则会正确打印出文件名。我在这里缺少什么?
编辑:'tagreement'字段在列表中的最后一个并不重要,我尝试将其移到其他字段之前,但它仍然无法正常工作。
print_r($_FILES)
:
Array (
[tidentity_proof] => Array (
[name] => cathypersons_deerdoe.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpcfeBC9
[error] => 0 [size] => 40299
)
[taddress_proof] => Array (
[name] => cheetah20cubs.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpRp4qu1
[error] => 0 [size] => 84873
)
[tidentity_proof2] => Array (
[name] => cheetah20cubs.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpCpGkmT
[error] => 0
[size] => 84873
)
[taddress_proof2] => Array (
[name] => cathypersons_deerdoe.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpBUBheL
[error] => 0
[size] => 40299
)
)
答案 0 :(得分:1)
在显示中看起来像您的字段名称,并且检查中的变量名称不一致。
你的第二段代码应该是:
if($_FILES['tidentity_proof']['name']=="" || $_FILES['taddress_proof']['name']=="" || $_FILES['tidentity_proof2']['name']=="" || $_FILES['taddress_proof2']['name']=="" || $_FILES['tagreement']['name']==""){
$_SESSION['message'].="You must upload files as identity proof.";
}