Coco! Multi file Uploader Widget

Requirement: Yii 1.1.11
if you are using a lower yii version then you will receive an error about "CJavaScriptExpression", please refer to issues about how to solve this issue.

Single & Multi File Uploads via Ajax-jQuery

Drag & Drop.

'Coco' is a widget for yii framework designed to handle File Uploads (Single and Multiple). Is designed using Ajax-jQuery and a well formed Architecture based on MVC (and UML). Using 'coco' is very simple, at first place you setup a fixed action in any controller, this action serves for all every coco-widgets in your application. At second place you insert the widget in your form, all uploaded files will be stored in the path provided by 'uploadDir' widget attribute. Very simple and usefull. Please enjoy it.

4) Insert and configure the Widget / Configura el Widget

[php]<?php$this->widget('ext.coco.CocoWidget',array('id'=>'cocowidget1', 'onCompleted'=>'function(id,filename,jsoninfo){ }', 'onCancelled'=>'function(id,filename){ alert("cancelled"); }', 'onMessage'=>'function(m){ alert(m); }', 'allowedExtensions'=>array('jpeg','jpg','gif','png'), // server-side mime-type validated 'sizeLimit'=>2000000, // limit in server-side and in client-side 'uploadDir' => 'assets/', // coco will @mkdir it // this arguments are used to send a notification // on a specific class when a new file is uploaded, 'receptorClassName'=>'application.models.MyModel', 'methodName'=>'onFileUploaded', 'userdata'=>$model->primaryKey, // controls how many files must be uploaded 'maxUploads'=>3, // defaults to -1 (unlimited) 'maxUploadsReachMessage'=>'No more files allowed', // if empty, no message is shown // controls how many files the can select (not upload, for uploads see also: maxUploads) 'multipleFileSelection'=>true, // true or false, defaults: true )); ?>

5) How to receive the uploaded file.

Coco will invoke an specific method name (methodName) in an specific class provided in widget config (receptorClassName). When a new file arrives from upload the Coco will invoke this method passing to you the 'userdata' argument and the full file path.

By example, suppose you have /protected/models/MyModel.php and you need the uploaded file arrives in this class, so the widget config will be: