Home > Article > PHP Framework > 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 = $('.file').get(0).files[0]; var data = new FormData(); data.append('business_license',business_license); $.ajax({ url:url, data:data, type:'POST', dataType:'json', 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, 'business_license'); $model->business_license->saveAs($model->business_license->baseName . '.' . $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!