Home  >  Article  >  PHP Framework  >  How to implement file upload in yii framework

How to implement file upload in yii framework

王林
王林Original
2020-02-26 16:32:452466browse

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" />

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

        }

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

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!

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