时间:2021-07-01 10:21:17 帮助过:3人阅读
use yii\web\UploadedFile;
$file = UploadedFile::getInstanceByName('photo');
//保存路径
$path = 'images/';
//判断文件是否存在
if(!file_exists($path)){
mkdir($path);
}
//重命名文件名
$file_name = date('Y-m-d').mt_rand(0000,9999).'.'.$file;
$new_path= $path.$file_name;
$file->saveAs($new_path,true);以上就介绍了 Yii20文件上传,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。