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