[Extension] Xupload

Thanks for your help Asgaroth. That worked a treat.

Unfortunately my client is using shared hosting and wants to be able to upload substantial files. I’ll have to figure something else out or convince him to move to a VPS.

Cheers.

very good extension , i can upload my images now , but How can i insert in the database the images attributes?

like:

Imagem = new Imagem;

imagem = post;

imagem.save();

in witch contronller i put it ?

Hello.

Can somebody tell me how to use xupload with the UI parameters?

I need to show one small thumb of the image sent and didn´t understand how it works with Yii.

Thanks

Leo

hey guys im trying this widget and i m having problem getting the name of image in my controller

model : [ my $model is the user model in my app]





    <?php

      

        $this->widget('ext.xupload.XUploadWidget', array(

            'url' => Yii::app()->createUrl("User/Upload/".$model->id),

            'model' => $model,

            'attribute' => 'Avatar',

            


        ));

        ?>






controller :




    public function actionUpload($id) {


        $model =  $_POST['User'];

         $fileName= $model->Avatar;

  

    }




any idea how can i get the name of uploaded file for example ? or any other feature like size and the upalod in in my own folder

Hi,

Relatively new to Yii I wonder how to get the xupload extension running under a module.

I currently have the extension in de app extensions folder, and the controllers/views too. And it works.

When I put the same controller/view behaviors inside a module, and click the green upload file button and select a file,

it won’t show the response below the button as before. So i think it breaks there.

Flow:

the widget form action refers to cms/gallery/upload

The upload action in the gallery controller is the same as before (when it worked)

So my question is, does it work differently when accessed from a module? And should the above situation work the same?

Hello,

Is this extension updated?

The demo and the extension looks different when i implemented it

The Yii extension uses V4 of the plugin, while there is a V5 now, so far I have no intention to update. Will do so If I get enough requests to do so.

Hi all,

I’ve installed this extension but it seems I get the none javascript version? Why is this happening?

Take a look at the included image. I’ve checked and jquery is loaded…

check firebug, you probably have some broken javascript, that is preventing the plugin from executing

Hi,

please any one tell me how to use this extension with send file and text data (Name,address) with single button. I already have form, I just want to send file and that data as ajax request

Hi Asgaroth,

Firstly, thank you for creating and sharing such a beautiful extension!

I have one problem, and one question:

The problem I have is this extension doesn’t work for me when I try to add the widget to an existing page. The Apache error I get is:

Call to a member function getType() on a non-object in /var/vhosts/test.local/www/protected/extensions/xupload/actions/XUploadAction.php on line 120

Everything works fine if I place the widget in its own view.

The question I have is: how do I theme the widget like the demo application (i.e. in the demo app you can select a theme from dropdown)?

Any help would be really appreciated.

Thanks.

I solved my problem thanks to Jesse (post #37). I hadn’t instantiated XUploadForm in my action handler:




  public function actionCreate()

  {

    $model=new DevRequest;

    $uploadModel = new XUploadForm;

    ...

    ...

    $this->render('create',array(

      'model'=>$model,

      'uploadModel' => $uploadModel,

    ));



(then don’t forget to pass $updateModel in your views/partial views too!!)

Also, you have to allow access to the ‘upload’ action in accessRules():




  return array(

    array('allow',  // allow all users to perform 'index' and 'view' actions

    'actions'=>array('index','view', 'upload'),

    'users'=>array('*'),

  ),



Still leaves my other question: how to theme XUploadWidget like the online demo (http://blueimp.github.com/jQuery-File-Upload/)?

Thanks.

Hi there,

I’m not entirely sure, but you should check the source code in the demo, it uses some CSS on its own, you can also try to use a different JUI theme.

What about auto-populating the Widget with the contents of a directory? Is that possible? For example, point the parent directory to something like images/uploads/01 and have the widget automatically populate itself with all files in images/uploads/01?

Not possible, not with the limitations of a browser uploader functionality.Ive never seen anything like that. there is no way to know what files on a users folder.

and if you are talking about server folders, then why would like to "upload" files from one folder to another in the same server?

Firstly, great extension Asgaroth.

Secondly, I’m trying to implement error handling and error responses as shown in the demo (try uploading a file that is not JPG, GIF or PNG or a file size over 5Mb and see what I mean) but having a hell of a time as my jQuery and JavaScript knowledge is very limited at best.

I can see in the demo code that there are jQuery vars set which describe the errors…




var fileUploadErrors = {

    maxFileSize: 'File is too big',

    minFileSize: 'File is too small',

    acceptFileTypes: 'Filetype not allowed',

    maxNumberOfFiles: 'Max number of files exceeded',

    uploadedBytes: 'Uploaded bytes exceed file size',

    emptyResult: 'Empty file upload result'

};



…but this isn’t integrated in the XUpload extension and I’m not sure how or where it should be placed. I also can figure out that this line…




<td class="error" colspan="2"><span class="label important">Error</span> {%=fileUploadErrors[file.error] || file.error%}</td>



…needs to be added to the _getBuildUploadRow() _getBuildDownloadRow() methods in the XUploadWidget.php file, so does that mean the file.error data is coming from the JSON data in the action file?

Any help appreciated, thanks :)

For those interested I slightly modified the model (i needed to)




$model->mime_type = $model->file->getType();

$mimext = explode("/", $model->mime_type);

$model->size = $model->file->getSize();

$model->name = $model->file->getName();

$model->extension = $model->file->getExtensionName();

$model->mime = $mimext[0];



Hi, I’m struggling also to make xupload my all in upload solution and I really think the upload action is quite basic compared to the php source file on the git repository of the jquery plugin.

My guess is to inspire ourselves with that code and adapt the XuploadAction before saving the file. But…not sure…

For example, I find the ‘trim_file_name’ function quite usefull in the case the filename lacks of extension or is messed up with dots. It can easily be part of the xupload controller action !

My guess is that you should have your main form with the data for your tables and have a field for your uploaded file.

On the other hand, you could have the xupload form apart and it will populate your other form on success upload.

That would be a kind of two steps procedures where you would commit the attachment of your file to its metadata (in this case your other form).

Adding the trim file to the xupload action




//from blueimp

private function trim_file_name($name, $type) {

        // Remove path information and dots around the filename, to prevent uploading

        // into different directories or replacing hidden system files.

        // Also remove control characters and spaces (\x00..\x20) around the filename:

        $file_name = trim(basename(stripslashes($name)), ".\x00..\x20");

        // Add missing file extension for known image types:

        if (strpos($file_name, '.') === false &&

            preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {

            $file_name .= '.'.$matches[1];

        }

        return $file_name;

    }



then in the run function




$model->name = $this->trim_file_name($model->file->getName(), $model->file->getExtensionName() );