search
Homephp教程php手册yii实现使用CUploadedFile上传文件的方法,yiicuploadedfile

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

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

一、前端代码

Html代码:

<form action="<&#63;php echo $this->createUrl('/upload/default/upload/');&#63;>" method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="hidden" name="dir" value="<&#63;php echo Yii::app()->controller->currentDir&#63;>"/>
<input type="submit" value="Upload Image"/>
</form>

二、后端代码

Php代码:

public function actionUpload()
{
$this->currentDir = isset($_REQUEST['dir']) &#63; $_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程序设计有所帮助。

您可能感兴趣的文章:

  • Yii框架登录流程分析
  • Yii中CGridView实现批量删除的方法
  • Yii基于数组和对象的Model查询技巧实例详解
  • yii权限控制的方法(三种方法)
  • yii使用activeFileField控件实现上传文件与图片的方法
  • Yii中Model(模型)的创建及使用方法
  • yii数据库的查询方法
  • Yii中实现处理前后台登录的新方法
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment