php如何判断文件是否上传,如何检查用户是否在PHP中上传文件?

您可以使用

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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值