您可以使用
is_uploaded_file():
if(!file_exists($_FILES['myfile']['tmp_name']) || !is_uploaded_file($_FILES['myfile']['tmp_name'])) {
echo 'No upload';
}
从文档:
如果由以下命名的文件,则返回TRUE:
filename was uploaded via HTTP POST.
This is useful to help ensure that a
malicious user hasn’t tried to trick
the script into working on files upon
which it should not be working–for
instance, /etc/passwd.
This sort of check is especially
important if there is any chance that
anything done with uploaded files
could reveal their contents to the
user, or even to other users on the
same system.
编辑:我使用这个在我的FileUpload类,万一它有帮助:
public function fileUploaded()
{
if(empty($_FILES)) {
return false;
}
$this->file = $_FILES[$this->formField];
if(!file_exists($this->file['tmp_name']) || !is_uploaded_file($this->file['tmp_name'])){
$this->errors['FileNotExists'] = true;
return false;
}
return true;
}