Yii 1.1: swfupload

Swfupload is a power and flexible upload engine write on javascript and actionscript now combined with yii framework.
15 followers

SWFUpload is a small JavaScript/Flash library to get the best of both worlds. It features the great upload capabilities of Flash and the accessibility and ease of HTML/CSS now combined with the power of Yii framework.

SwfUpload

Resources

Donate

Documentation

THANKS TO PRADHAN WHO TOLD ME ABOUT ONE BUG. TO GET RID OF IT, IF YOU HAVE DOWNLOADED THE EXTENSION BEFORE, JUST CHANGE ONE LINE ON YOUR CODE:

'upload_success_handler'=>'js:uploadSuccessListView' TO 'upload_success_handler'=>'js:uploadSuccess'.

Requirements

  • Yii 1.0 or above

Installation

  • Extract the release file under protected/extensions
  • Put the code bellow and

Usage

See the following code example:

On controller

$filedata=$_FILES['Filedata'];
@move_uploaded_file($filedata['tmp_name'],'path/to/folder'); // Not relative. Full path

On Views

<?php
$this->widget('application.extensions.swfupload.CSwfUpload', array(
    'jsHandlerUrl'=>'path/to/handler.js', //Relative path
    'postParams'=>array(),
    'config'=>array(
        'use_query_string'=>true,
        'upload_url'=>'/path/to/controller/action', //Use $this->createUrl method or define yourself
        'file_size_limit'=>'2 MB',
        'file_types'=>'*.jpg;*.png;*.gif',
        'file_types_description'=>'Image Files',
        'file_upload_limit'=>0,
        'file_queue_error_handler'=>'js:fileQueueError',
        'file_dialog_complete_handler'=>'js:fileDialogComplete',
        'upload_progress_handler'=>'js:uploadProgress',
        'upload_error_handler'=>'js:uploadError',
        'upload_success_handler'=>'js:uploadSuccess',
        'upload_complete_handler'=>'js:uploadComplete',
        'custom_settings'=>array('upload_target'=>'divFileProgressContainer'),
        'button_placeholder_id'=>'swfupload',
        'button_width'=>170,
        'button_height'=>20,
        'button_text'=>'<span class="button">'.Yii::t('messageFile', 'ButtonLabel').' (Max 2 MB)</span>',
        'button_text_style'=>'.button { font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif; font-size: 11pt; text-align: center; }',
        'button_text_top_padding'=>0,
        'button_text_left_padding'=>0,
        'button_window_mode'=>'js:SWFUpload.WINDOW_MODE.TRANSPARENT',
        'button_cursor'=>'js:SWFUpload.CURSOR.HAND',
        ),
    )
);
?>
 
<?php echo CHtml::beginForm(); ?>
<div class="form">
    <div class="row">
    <div id="divFileProgressContainer"></div>
    <div class="swfupload"><span id="swfupload"></span></div>
    </div>
</div>
<?php echo CHtml::endForm(); ?>

Change Log

July 16, 2010

  • Initial release.

July 25, 2010

  • Solved bug on javascript handlers example file.

Total 8 comments

#8063 report it
jiaming at 2012/05/07 10:48pm
Database

Any ideas about how to save files to database.....?

#7763 report it
lvil at 2012/04/16 10:58am
302 error

I always get alert message with "302" written in it after uploading file. Looks like my controller/action is not found. But I can easily access it with url. What can be wrong?

#7345 report it
MetaYii at 2012/03/15 04:24pm
Cleanup

Like @tonydspaniard I also made some changes:

  1. major code cleanup.
  2. bundled the handlers and CSS and made optional whether to use them or not.

PM is you're interested in the code (I wouldn't like to post it as a new extension)

#6222 report it
qsrtlwe at 2011/12/20 04:49am
FBGallery

Hi! How can i use this with FBGallery?

#3473 report it
thiagovidal at 2011/04/14 10:09am
e6nian

actually i forgot the ...php.

#3472 report it
thiagovidal at 2011/04/14 10:07am
hey

thanks for comments. please could u forward the code to me?

#3451 report it
yes.yii at 2011/04/13 10:16pm
you made a bad example of this with short tag of php
<?
$this->widget

you'd better never use short tag in php.

#1928 report it
Antonio Ramirez at 2010/10/16 08:14pm
grrreat!

Thank you very much!

I had to include swfupload onto my new project and it was quite easy to implement.

I did a couple of changes though:

a) made handlers.js to be part of the assets as the images folder and its css b) in handlers.js i have changed the lines where it points to a specific location for pictures such as error.gif to a variable that i set to published assets. c) added support for button_image_url but hidden

it just works nice and smooth... thanks

if you want the code i forward it to you... just PM

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: Other Open Source License
  • Developed by: thiagovidal
  • Category: Others
  • Votes: +7 / -1
  • Downloaded: 7,532 times
  • Created on: Jul 16, 2010
  • Last updated: Apr 14, 2011