yii實(shí)現(xiàn)使用CUploadedFile上傳文件的方法
本文實(shí)例講述了yii實(shí)現(xiàn)使用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)); }
關(guān)于CUploadedFile類的使用:
通過
或
獲取的對(duì)象$attach對(duì)象,有以下幾個(gè)屬性:
name
size
type
tempName
error
extensionName
hasError
希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
smarty中改進(jìn)truncate使其支持中文的方法
這篇文章主要介紹了smarty中改進(jìn)truncate使其支持中文的方法,涉及針對(duì)Smarty源碼中truncate源文件進(jìn)行函數(shù)功能擴(kuò)展的相關(guān)技巧,需要的朋友可以參考下2016-05-05php實(shí)現(xiàn)ffmpeg處理視頻的實(shí)踐
本文主要介紹了php實(shí)現(xiàn)ffmpeg處理視頻的實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12