Home > PHP Framework > YII > body text

How to implement file upload in yii framework

王林
Release: 2020-02-26 16:32:45
Original
2466 people have browsed it

How to implement file upload in yii framework

1. First, download the uploadFile class from the yii framework

2. HTML code

<input type="file" class="file" style="display: none" name="business_license" />
Copy after login

(recommended tutorial: yii framework)

3. js code

var business_license = $(&#39;.file&#39;).get(0).files[0];
var data = new FormData();
data.append(&#39;business_license&#39;,business_license);
$.ajax({
        url:url,
        data:data,
        type:&#39;POST&#39;,
        dataType:&#39;json&#39;,
        processData: false,
        contentType: false,
        success:function(response){

        },
        error:function(response){
            // console.log(response);

        }
Copy after login

4. PHP receiving

$model = new Model();//实例化数据库模型
$model->business_license = UploadedFile::getInstance($model, &#39;business_license&#39;);
$model->business_license->saveAs($model->business_license->baseName . &#39;.&#39; . $model->business_license->extension);
Copy after login

The final generated file address is the path under saveAs, which can be modified freely.

For more programming related content, please pay attention to the Programming Introduction column on the php Chinese website!

The above is the detailed content of How to implement file upload in yii framework. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!