A simple action for XUpload extension

All the basic functionality for an action used by the xupload extension. Check resources for the source code of this action

Prologue

A file uploader is commonly a web application must have. There are pretty enough extensions in the yii project to achieve (other use flash, other are jquery...). I was suggested to use the xupload. After checking the project code, i noticed the action code that handles the request from the user.

"Do not repeat yourself"

Sticking with this motto, and due to the fact I did not want every controller that needs something to be uploaded to have that code plain in it, I created this CAction class. 99% of the code belongs to the xupload author Asgaroth.

"This action is Needless!"

Many of you may think that this CAction is needless, this is somehow true. You could create a controller like XuploadController.php have all the upload actions in there and pass this controller/action to the xupload url property. Even this case you are one step beyond, just create the XuploadController and use this action as in any other controller:

class MyController exnteds CController 
{
    public function actions()
    {
        return array(
            'upload'=>array(
                //Assuming action exist in the extension folder
                'class'=>'ext.EXUploadAction',
            ),
        );
    }
}
Ending

This code is not complicated neither is big enough. There are only 2 properties:

  • parent_id: Parent folder where the file will be uploaded.
  • path: Full path of the main uploading folder. Check code and EXUploadAction::init() for more informatin.
Resources
3 0
5 followers
Viewed: 20 610 times
Version: 1.1
Category: Tips
Written by: tydeas_dr
Last updated by: tydeas_dr
Created on: Apr 26, 2011
Last updated: 13 years ago
Update Article

Revisions

View all history

Related Articles