Home > Backend Development > PHP Tutorial > yii implements the method of uploading files using CUploadedFile, yiicuploadedfile_PHP tutorial

yii implements the method of uploading files using CUploadedFile, yiicuploadedfile_PHP tutorial

WBOY
Release: 2016-07-12 09:02:16
Original
1022 people have browsed it

yii implements the method of uploading files using CUploadedFile, yiicuploadedfile

This article describes the example of yii implementing the method of using CUploadedFile to upload files. Share it with everyone for your reference, the details are as follows:

1. Front-end code

Html code:

<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>

Copy after login

2. Backend code

Php code:

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));
}

Copy after login

About the use of CUploadedFile class:

Copy the code via The code is as follows: CUploadedFile::getInstance($model,'album_image');
Or Copy the code The code is as follows: $attach = CUploadedFile::getInstanceByName($inputFileName);

The obtained object $attach object has the following attributes:

name
size
type
tempName

error
extensionName
hasError

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

Articles you may be interested in:

  • Yii framework login process analysis
  • How to implement batch deletion of CGridView in Yii
  • Yii based on arrays and objects Detailed explanation of model query skills examples
  • Yii permission control methods (three methods)
  • Yii uses the activeFileField control to implement the method of uploading files and pictures
  • Model in Yii Creation and usage methods
  • Yii database query method
  • A new method of handling front and backend logins in Yii

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1085888.htmlTechArticleyii implements the method of uploading files using CUploadedFile, yiicuploadedfile This example describes the method of yii implementing using CUploadedFile to upload files. Share it with everyone for your reference, specifically...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template