Cmultifileupload is used to upload files and supports uploading multiple files at once. This UI component is based on the jquery Multi File Upload plug-in. Many of the UI components built into Yii are based on jquery, so you need to create a assets directory to store dynamically generated javascripts.
The uploaded file information can be accessed through $_files[widget-name], for example, the file information uploaded by Cmultifileupload's name "files" can be accessed by $_files [' Files ']. In addition, the form property containing the cmultifileupload needs to be set enctype=multipart/form-data.
This example creates a upload directory to store uploaded files. We import the directory through the profile settings in the upload file.
Modify/config/main.php Add Project code
Application-level parameters that can is accessed
//Using Yii::app ()->params[' paramname '] ' params ' =>
Require (DirName (__file__). /params.php '),
Add some parameters to the application, and the file that holds the parameters is config/param.php
The directory that defines the uploaded files is as follows:
This contains the application parameters the can is
maintained via GUI return
Array (
//upload directory
' Uploaddir ' => ' upload/',
);
You can access this parameter in code by Yii::app ()->params[' Uploaddir ', and for this simple example, you can use upload/as a fixed constant without having to define application parameter params.
This example does not need to use model, we define view as follows:
<center class= "Form" > <?php $form = $this->beginwidget (' Cactiveform ', Array (' method ' =& gt; '
Post ', ' Htmloptions ' =>array (' enctype ' => ' multipart/form-data '));?>
<?php $this->widget (' Cmultifileupload ', Array (' name ' => ' files ', ' Accept ' => ' jpg|png '), ' Max ' =>3, ' remove ' => ' remove ',//' denied ' => ', message This is displayed when a file type is Not allowed//' duplicate ' => ', the message this is displayed when a file appears twice ' Htmloptions ' => ; Array (' Size ' =>25));?> <center class= "row Submit" > <?php echo C Html::submitbutton (' Upload ');?> </center> <?php $this->endwidget ();?>
;/center><!--form--> <ul> <?php foreach ($this->findfiles () as $filename):?> <li><?php Echo Chtml::link ($filename, Yii::app ()->baseurl. /'. Yii::app ()->params[' Uploaddir ']. $filename, Array (' rel ' => ' external '));? ></li> <?php Endforeach;?> </ul>