muploadify use uploadify in your application - a jQuery file upload plugin script

  1. Requirements
  2. Usage
  3. Notes
  4. Options
  5. Version
  6. Resources

widget that integrates uploadify in your application - a jQuery file upload plugin script

Requirements

Yii 1.1 or above

Usage

Usage with model:

//view
$this->widget('MUploadify',array(
  'model'=>$model,
  'attribute'=>'myAttribute',
  //'script'=>$this->createUrl('upload'),
  //'auto'=>true,
  //'someOption'=>'someValue',
));

//controller
function init(){
  if(isset($_POST['SESSION_ID']){
    $session=Yii::app()->getSession();
    $session->close();
    $session->sessionID = $_POST['SESSION_ID'];
    $session->open();
  }
}
function actionUpload(){
  $model=new myModel;
  if(isset($_POST['myModel'])){
    $model->myAttribute=CUploadedFile::getInstance($model,'myAttribute');
    if(!$model->save() || !$model->myAttribute->saveAs('someFile.jpg'))
      throw new CHttpException(500);
    echo 1;
    Yii::app()->end();
  }
}

using without model:

//view
$this->widget('MUploadify',array(
  'name'=>'myPicture',
  //'buttonText'=>Yii::t('application','Upload a picture'),
  //'script'=>array('myController/upload','id'=>$model->id),
  //'checkScript'=>array('myController/checkUpload','id'=>$model->id),
  //fileExt=>'*.jpg;*.png;',
  //fileDesc=>Yii::t('application','Image files'),
  //'uploadButton'=>true,
  //'uploadButtonText'=>'Upload new',
  //'uploadButtonTagname'=>'button',
  //'uploadButtonOptions'=>array('class'=>'myButton'),
  //'onAllComplete'=>'js:function(){alert("Pictures uploaded!";);}',
));

//controller
function init(){
  if(isset($_POST['SESSION_ID']){
    $session=Yii::app()->getSession();
    $session->close();
    $session->sessionID = $_POST['SESSION_ID'];
    $session->open();
  }
}
function actionUpload(){
  if(isset($_POST['myPicture'])){
    $myPicture=CUploadedFile::getInstanceByName('myPicture');
    if(!$myPicture->saveAs('someFile.ext'))
      throw new CHttpException(500);
    echo 1;
    Yii::app()->end();
  }
}

Notes

  • use uploadify events prepending 'js:' to its value, like this :

'onAllComplete'=>'js:function(){alert("Done!";);}',

  • you must echo 1 in the controller or it will bug the progress bar (this is a uploadify bug)

Options

string $sessionKey='SESSION_ID'

The key that will contain the session id so you can retrieve later by $_POST['SESSION_ID']

boolean $uploadButton=null

wheter to generate a button to trigger the upload. If null, it will generate the button if uploadify 'auto' option is not set or is false

array $uploadButtonOptions=array()

html options of the upload button

string $uploadButtonTagname='a'

the name of the html tag to generate the upload button

string $uploadButtonText='Upload files'

the text to be used in the upload button

mixed $script

The path to the back-end script that will process the file uploads. The path can be either an array or a string. See CHml::normalizeUrl.

See also the uploadify documentation

Defaults to the active url.

mixed $checkScript

The path to the back-end script that checks for pre-existing files on the server. The path can be either an array or a string. See CHml::normalizeUrl.

See also the uploadify documentation

Defaults to null, disabling this option.

mixed $scriptData

An object containing name/value pairs with additional information that should be sent to the back-end script when processing a file upload.

The data is json encoded and can be later retrieved by json decoding $_POST['attribute'] or $_POST['model']['attribute']

any other uploadify option

Version

  • Version 0.1 (20/08/2011): Initial release. It uses uploadify lastest stable version 2.1.4

Resources

12 2
26 followers
3 026 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: Gustavo
Created on: Aug 20, 2011
Last updated: 12 years ago

Downloads

show all

Related Extensions