yii实现使用CUploadedFile上传文件的方法,yiicuploadedfile
本文实例讲述了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程序设计有所帮助。
您可能感兴趣的文章:
- 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
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks agoByDDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks agoByDDD
Where to find the Crane Control Keycard in Atomfall
3 weeks agoByDDD
Saving in R.E.P.O. Explained (And Save Files)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment