widget that integrates uploadify in your application - a jQuery file upload plugin script
Yii 1.1 or above
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(); } }
'onAllComplete'=>'js:function(){alert("Done!";);}',
The key that will contain the session id so you can retrieve later by $_POST['SESSION_ID']
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
html options of the upload button
the name of the html tag to generate the upload button
the text to be used in the upload button
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.
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.
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']
Total 4 comments
Good one! I didn't like the controller init override though so I looked for an alternative. Since muplodify default session handler is same as php's default session handler all I had to do is to turn on transparent session id when appropriate. Config file:
I'm glad you liked and it was useful for you.
As soon as I have time I'll update the extension with your fix.
As for the multi option, it is in the uploadify documentation, like many other options. I only posted a link here to it so I would'nt have to copy it all here and change every time it changes.
As for updates, I'll update as needed or when a new stable uploadify version is releasead.
This extension is much better than other two. Do not forget about updates. Thanks!
Love this one over the other one. A bit more documentation would be nice. For example: Multi. I figured this out. You may 1 request PER FILE to the Url specified. This is fine ( I just want to spell it out ). Also if this form is embedded in a page you have a jump problem because the "a href="#" is not returning false. This is a tiny oversight - because you can override this in the settings so it's not major... but may I recommend changing line 211 to:
$this->uploadButtonOptions['onclick']="javascript:$('#{$this->inputId}').uploadifyUpload(); return false;"; ??
Return false stops the jump to the top of the screen. Thanks!
( edited because the HTML I added messed the comment up )
Leave a comment
Please login to leave your comment.