如何验证上传文件大小最多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,这更具可读性,您无需进行任何计算(对于更复杂的度量单位,这是更好的选择).
有用的链接: