加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

yii2 – 如何验证文件上传最大大小500KB

发布时间:2020-12-13 17:51:18 所属栏目:PHP教程 来源:网络整理
导读:如何验证上传文件大小最多500Kb? 我做得很好,但它没有成功: public function rules() { return [... 'myfile' ],'file','extensions' = 'pdf,jpg','maxSize' = 4096000,'tooBig' = 'Limit is 500KB' ],]; } 您指定了错误的maxSize. 来自官方文档: The max
如何验证上传文件大小最多500Kb?
我做得很好,但它没有成功:
public function rules()
    {
        return [
...
           'myfile'
            ],'file','extensions' => 'pdf,jpg','maxSize' => 4096000,'tooBig' => 'Limit is 500KB' ],];
    }
您指定了错误的maxSize.

来自官方文档:

The maximum number of bytes required for the uploaded file. Defaults
to null,meaning no limit. Note,the size limit is also affected by
‘upload_max_filesize’ INI setting and the ‘MAX_FILE_SIZE’ hidden field
value.

See also $tooBig for the customized message for a file that is too
big.

500千字节是500 * 1024字节= 512 000字节.

public function rules()
{
    return [
        ['myfile','maxSize' => 512000,'tooBig' => 'Limit is 500KB'],];
}

您也可以将其指定为’maxSize’=> 500 * 1024,这更具可读性,您无需进行任何计算(对于更复杂的度量单位,这是更好的选择).

有用的链接:

> What is kilobyte?
> FileValidator $maxSize

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读