Yii20 file upload

WBOY
WBOYOriginal
2016-07-28 08:26:40921browse

1. Load in the controller interface

use yii\web\UploadedFile;

2. Receive the picture and save it locally

  $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);

Note: At this point the file has been uploaded. The next step is to add the database

The above introduces Yii20 file upload, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn