xupload

jquery file upload extension for yii
133 followers

Demo

jQuery file upload extension for Yii, allows your users to easily upload files to your server:

Setup instructions

Using composer

Add to your composer.json

{
    "config": {
        "vendor-dir": "protected/extensions/vendor"
    },
    "repositories": [
        ... //Other repositories
        {
            "type": "vcs",
            "url": "https://github.com/Asgaroth/xupload.git"
        }
    ],
    "require": {
        ... //Other packages
        "Asgaroth/xupload": "v0.5.0"
    }
}

Manually

Download the files and extract them to you project desired folder

Configuration

  1. Add an application alias in you application configuration that points to the extracted folder
// protected/config/main.php
...
'import'=>array(
    'application.models.*',
    'application.components.*',
),
'aliases' => array(
    //If you used composer your path should be
    'xupload' => 'ext.vendor.Asgaroth.xupload'
    //If you manually installed it
    'xupload' => 'ext.xupload'
),
  1. Create a model, declare an attribute to store the uploaded file data, and declare the attribute to be validated by the 'file' validator. Or use XUploadForm
  2. Create a controller to handle form based file uploads. Or use XUploadAction
  3. Add the Widget to you view
<?php
$this->widget('xupload.XUpload', array(
                    'url' => Yii::app()->createUrl("site/upload"),
                    'model' => $model,
                    'attribute' => 'file',
                    'multiple' => true,
));
?>

Info: Ensure that the apache server has write permissions in the folder you are uploading the files, XUpload will try to create the upload folder if it doesn't exist already.

Using XUploadAction and XUploadForm:

  • XUploadAcion adds basic upload functionality to any controller.
  • XUploadForm its a simple form model to store uploaded file data
  1. Override CController::actions() and register an action of class XUploadAction we (will use 'upload' for the examples), and configure its properties:
//protected/controllers/SiteController.php
class SiteController extends CController
{
    public function actions()
    {
        return array(
            'upload'=>array(
                'class'=>'xupload.actions.XUploadAction',
                'path' =>Yii::app() -> getBasePath() . "/../uploads",
                'publicPath' => Yii::app() -> getBaseUrl() . "/uploads",
            ),
        );
    }
}
  1. Create an initial action that will render the form using the XUploadModel:
//protected/controllers/SiteController.php
public function actionIndex() {
        Yii::import("xupload.models.XUploadForm");
        $model = new XUploadForm;
        $this -> render('index', array('model' => $model, ));
    }

Additional Documentation

Here is a wiki describing a more complex workflow using this widget.

And a wiki explaining how to send additional data with your file

Note: See the attached project for more examples

Resources

Changelog

v0.5.0 Sat Nov 10 19:17:16 COT 2012

  • Added $formClass to XUploadAction, to allow overwriting the default form class
  • Improved location of thumbnail url handling
  • Improved security
  • Setup public variables to make using other form models / Active Record models easier.
  • JavaScript-part of extension now properly depends on XUpload::$multiple parameter
  • Added I18N support, added russian translation
  • Fixed incorrect behavior when XUploadAction::$subfolderVar was false
  • No script files are now loading from github.com/blueimp, all of them are locally available now
  • Added XUpload::$showForm param - this allows easily avoid rendering tag in widget view

v0.4.0 Mon Jul 2 16:25:53 COT 2012

  • Added image preview assets
  • Added image processing assets
  • Added the ability to specify upload, download, and form views

v0.3a Sun Mon Apr 2 21:43:38 COT 2012

  • Fixed missing dependencies

v0.3 Sun Apr 1 18:35:23 COT 2012

  • Updated to the new jquery plugin version

v0.2 Sun May 8 19:28:43 COT 2011

  • Added Multiple file uploading functionality
  • Integrated XUploadAction with a few changes (thanks to tydeas_dr)
  • Moved XUploadForm to the extension folder

v0.1 Mon Mar 21 14:51:13 COT 2011

  • First release

Colaborators

License

Released under the MIT license.

Total 20 comments

#13363 report it
fr0d0z at 2013/05/24 12:07pm
RE: not working in IE9

Pretty sure uploads are working fine on our system for IE 9 (haven't tested IE 10 yet)

#13361 report it
haymps at 2013/05/24 08:14am
RE: not working in IE9

It works for me in IE10. Does it work for anyone with IE9?

#13354 report it
greed at 2013/05/24 02:54am
IE9

it doesn't work in IE at all! I was upset.

#13224 report it
njasm at 2013/05/16 04:51am
Does this extension work with IE ?

does the latest version work with IE 9+ ?

#13111 report it
Edson Rodrigues at 2013/05/05 02:40pm
Javascript library update

The extension is very good, more could update javascript and extension because it has several options, and the process method that resizes the image and between several. thanks

#12910 report it
myrazel at 2013/04/20 04:12am
no doubt its awesome

good and nice extension

#12650 report it
Asgaroth at 2013/04/03 02:12pm
@venuk

Not that I know of, that line should't throw any error, please ask in the forum, and provide all relevant information.

#12649 report it
venuk at 2013/04/03 01:21pm
Any changes required with dbsession?

Asgaroth, I think this is the only thing I need to fix with xupload before it is working perfectly.

I have enabled db session in the main.php with below code, then multiple files state is not maintaining. Code causing error : $userFiles = Yii::app()->user->getState($this->stateVariable, array());

so it is throwing error in firebug and not deleting all the files. Do I need to modify anything to use db sesssion?

#12202 report it
manoj20 at 2013/03/06 04:09am
error

i am able to bring up the extension, but when i add files the files are not showing up, any suggesstion, this one is also not saving in my upload folder.

#12163 report it
fr0d0z at 2013/03/02 06:36pm
@happyjim

Did you add in the upload action to your controller actions array? Probably worth starting there if you haven't. If you do, you should get some errors back from the server's Ajax response. If you need more help though, it's better to discuss on the forum.

#12162 report it
hippyjim at 2013/03/02 03:19pm
Does nothing

The demo looks great, but it doesn't do a lot when I installed it.

I added the widget to my form as directed above and the buttons rendered on the page. I hit "Add files" which opened a file dialog, chose a file, and hit "Open".

The dialog closed and nothing else happened. No error messages, no network requests, nothing. Without an error message, it's a bit hard to debug - any ideas what's wrong, or at least a clue where I should look?

#12121 report it
venuk at 2013/02/27 08:30pm
In mac it needs write access on parent folder of where you are uploading

Great extension. thanks Asgaroth.

After start uploading , the photo is displaying in big size, any option to display it as in the preview? before clicking on start upload?

#11985 report it
fr0d0z at 2013/02/18 11:06am
re: json return value expected,key 'files' expected

@drumaddict: if you can post your issue to the Github repo / add a pull request, would love to get those bugs fixed ...

#11976 report it
drumaddict at 2013/02/17 09:43am
json return value expected,key 'files' expected

I replaced assets with the newer version.Files get uploaded but the callback gives an error.Looked at the demo and now it seems that the plugin expects the json indexed by files,like so

echo json_encode(array('files'=>array( array(
                       'name' => $model->{$this->displayNameAttribute},
                       'type' => $model->{$this->mimeTypeAttribute},
                        'size' => $model->{$this->sizeAttribute},
                        'url' => $this->getFileUrl($model->{$this->fileNameAttribute}),
                        'thumbnail_url' => $model->getThumbnailUrl($this->getPublicPath()),
                        'delete_url' => $this->getController()->createUrl($this->getId(), array(
                            '_method' => 'delete',
                            'file' => $model->{$this->fileNameAttribute},
                        )),
                        'delete_type' => 'POST'
                   ))));

After fixing that,the callback gave no error.Yet,the uploaded preview images are the full images by default.Still more editing to do,to make it work.

#10056 report it
Asgaroth at 2012/10/02 02:13pm
@Rajib Rakhmit

Not sure what the problem its, why does it says "xupload.url" in lowercase?

Please use the forum for this kind of questions

#10055 report it
Rajib Rakhmit at 2012/10/02 01:47pm
I get a error Plz help me

Property "xupload.url" is not defined.

_** My Code is:**_

$this->widget('xupload.XUpload', array(
         'url' => Yii::app()->createUrl("site/upload"),
         'model' => $model,
         'attribute' => 'file',
         'multiple' => true,
 ));
#9757 report it
shafi at 2012/09/08 08:45am
hi @yiqing95

hi go for extensions/actions/xuploadactions u ll find the controller and the destination..or u can edit the extensions/xupload/view/download .php and put ur target folder.the destination file is some what named uploads..if such a file does not exists in the application root folder www/testdrive/uploads create it.the file will be uploaded to that folder..

plz encourage me by likes or comment...i m a newbie to yii and these types of forums...

#9756 report it
shafi at 2012/09/08 08:36am
hi xNicox

the image is not storing in to the database...it stores to some files that u can search in the application folder.sometimes named uploads or create that folder in the application root folder in the name->means www/testdrive/uploads

#9755 report it
shafi at 2012/09/08 08:31am
i m newbie ..please like me i can give some answers

hi dears go to download.php there u can find the target file name...or go to xupload action there also u can change file name and target folder...if anyone got help by this like me or comment...i m new to yii and to this type of forums...

#9754 report it
shafi at 2012/09/08 08:25am
for resizing thumb nail

go to download.php inside extensions/view/download.php ---> there is an

<a href="something"  <img src="{% something %}" /> </a>

please give height width parameters...

Leave a comment

Please to leave your comment.

Create extension