Home >Backend Development >PHP Tutorial >Yii20 file upload
1. Load in the controller interface
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);
The above introduces Yii20 file upload, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.