我想检查用户是否使用表单上传了图像
我试过:
if (empty($_FILES['txtImage'])) {
$msg = 'Opss, you forgot the image.';
}
由于PHP 4.2.0,PHP将返回一个适当的错误代码和文件数组。
所以,
<?php
if ($_FILES['txtImage']['error'] === UPLOAD_ERR_NO_FILE) {
$msg .= "Opss, you forgot the image.<br>";
}
?>
http://php.net/manual/en/features.file-upload.errors.php
http://www.php.net/is_uploaded_file
if(!file_exists($_FILES['myfile']['tmp_name']) || !is_uploaded_file($_FILES['myfile']['tmp_name'])) {
echo 'No upload';
}
此外,您可以使用getimagesize()进行检查,如果它返回FALSE,则它不是图像
https://stackoverflow.com/a/946432/1172872