一、前端代码
二、后端代码
关于CUploadedFile类的使用
通过 CUploadedFile::getInstance($model,'album_image');
或 $attach = CUploadedFile::getInstanceByName($inputFileName);
获取的对象$attach对象,有以下几个属性:
name
size
type
tempName
error
extensionName
hasError
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>
<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));
}
{
$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