您好我在提交表单之前尝试验证用户是否上传了文件。它只是说每次都没有上传文件。这适用于文本但不适用于文件。
HTML
<li>
<label for="uthumb">Image of chair 120 x 200:</label>
<input type="file" name="uthumb"/>
<div class="errorAdd"><?php echo $errorThumb; ?></div>
</li>
<li>
<label for="uthumb">Large Image of chair 400 x 500:</label>
<input type="file" name="ulrgthumb"/>
<div class="errorAdd"><?php echo $errorImg; ?></div>
</li>
PHP
$newThumb='';
$newimg='';
if(empty($_POST['uthumb'])){
$all_valid = false;
$errorThumb = 'We need a thumbnail';
}else{
$newThumb=$_POST['uthumb'];
}
if(empty($_POST['ulrgthumb'])){
$all_valid = false;
$errorImg = 'We need a large image';
}else{
$newimg=$_POST['ulrgthumb'];
}
}
答案 0 :(得分:4)
您需要使用$ _FILES数组,而不是$ _POST数组:File upload
答案 1 :(得分:3)
你想检查
$_FILES
不
$_POST
http://php.net/manual/en/features.file-upload.php
$newThumb='';
$newimg=''; if(empty($_FILES['uthumb'])){
$all_valid = false;
$errorThumb = 'We need a thumbnail';
}else{
$newThumb=$_FILES['uthumb'];
} if(empty($_FILES['ulrgthumb'])){
$all_valid = false;
$errorImg = 'We need a large image';
}else{
$newimg=$_FILES['ulrgthumb'];
}
答案 2 :(得分:0)