当前位置: 移动技术网 > IT编程>开发语言>PHP > yii实现使用CUploadedFile上传文件的方法

yii实现使用CUploadedFile上传文件的方法

2018年04月20日  | 移动技术网IT编程  | 我要评论

本文实例讲述了yii实现使用cuploadedfile上传文件的方法。分享给大家供大家参考,具体如下:

一、前端代码

html代码:

<form action="<?php echo $this->createurl('/upload/default/upload/');?>" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="hidden" name="dir" value="<?php echo yii::app()->controller->currentdir?>"/>
<input type="submit" value="upload image"/>
</form>

二、后端代码

php代码:

public function actionupload()
{
$this->currentdir = isset($_request['dir']) ? $_request['dir'] : '';
$image = cuploadedfile::getinstancebyname('file');
$name = $this->uploadpath.'/'.$this->currentdir.'/'.$image->name;
$image->saveas($name);
$this->redirect(array('index','dir'=>$this->currentdir));
}

关于cuploadedfile类的使用:

通过

复制代码 代码如下:
cuploadedfile::getinstance($model,'album_image');

复制代码 代码如下:
$attach = cuploadedfile::getinstancebyname($inputfilename);

获取的对象$attach对象,有以下几个属性:

name
size
type
tempname

error
extensionname
haserror

希望本文所述对大家基于yii框架的php程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网