本文实例讲述了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类的使用:
通过
获取的对象$attach对象,有以下几个属性:
name
size
type
tempname
error
extensionname
haserror
希望本文所述对大家基于yii框架的php程序设计有所帮助。
如对本文有疑问, 点击进行留言回复!!
网友评论