Home > Backend Development > PHP Tutorial > Yii20 file upload

Yii20 file upload

WBOY
Release: 2016-07-28 08:26:40
Original
932 people have browsed it

1. Load in the controller interface

use yii\web\UploadedFile;
Copy after login

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);
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template