Yii implements how to use CUploadedFile to upload files. yiicuploadedfile_PHP tutorial

Source: Internet
Author: User
Yii implements the file upload method using CUploadedFile, yiicuploadedfile. Yii implements the method of using CUploadedFile to upload files. yiicuploadedfile this article describes how yii implements the method of using CUploadedFile to upload files. For your reference, see yii for how to use CUploadedFile to upload files. yiicuploadedfile

This example describes how to use CUploadedFile to upload files in yii. We will share this with you for your reference. The details are as follows:

I. front-end code

Html code:

 

II. backend code

Php code:

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

Usage of the CUploadedFile class:

Pass The code is as follows: CUploadedFile: getInstance ($ model, 'Album _ image ');
Or The code is as follows: $ attach = CUploadedFile: getInstanceByName ($ inputFileName );

The obtained $ attach object has the following attributes:

Name
Size
Type
TempName

Error
ExtensionName
HasError

I hope this article will help you design PHP programs based on the Yii Framework.

Articles you may be interested in:
  • Yii Framework logon process analysis
  • Batch delete of CGridView in Yii
  • Yii provides an example of array and object-based Model query techniques.
  • Yii permission control methods (three methods)
  • Yii uses the activeFileField control to upload files and images
  • How to create and use a Model in Yii
  • Yii database query method
  • Yii implements a new method for handling frontend and backend logins

Examples in this article describes how yii uploads files using CUploadedFile. Share it with you for your reference, as shown in...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.