[Extension] Xupload

OK, thanx, this was an useful info. I finally figured out, what was the problem: in FileManagerController, simply create new action ‘Upload’ and insert in it this code:


return array(

            'upload'=>array(

                'class'=>'xupload.actions.XUploadAction',

                'path'=>Yii::getPathOfAlias('webroot') . "/images",

                'publicPath'=>Yii::getPathOfAlias('webroot') . "/images",

            ),

        );

And of cource allow it in ‘accessRules’.

Now, what means error: ‘Empty file upload result’? Is that because I’m using model default template?

I dont know, where are you seeing this error?

Directly in the upload block, where error messages are shown. No errors in console.

I am getting a ERROR. Please help me.

ERROR IS "Property "xupload.url" is not defined.

My Controller Name is "XuploadController.php" and Code is




<?php


class XuploadController extends Controller

{

	public function actionIndex()

	{

		Yii::import("xupload.models.XUploadForm");

		

		$model = new xupload();

		

		$this -> render('index', array('model' => $model, ));

	}


	// Uncomment the following methods and override them if needed

	

	public function actions()

	{

		// return external action classes, e.g.:

		return array(

			

			'upload'=>array(

                'class'=>'xupload.actions.XUploadAction',

                'path' =>Yii::app() -> getBasePath() . "/../uploads",

                'publicPath' => Yii::app() -> getBaseUrl() . "/uploads",

            ),

		);

	}

	

}



My Model Name is "xupload.php" and code is




<?php


/**

 * This is the model class for table "xupload".

 *

 * The followings are the available columns in table 'xupload':

 * @property integer $id

 * @property string $fileName

 * @property string $description

 * @property string $extraId

 */

class xupload extends CActiveRecord

{

	/**

	 * Returns the static model of the specified AR class.

	 * @return xupload the static model class

	 */

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	/**

	 * @return string the associated database table name

	 */

	public function tableName()

	{

		return 'xupload';

	}


	/**

	 * @return array validation rules for model attributes.

	 */

	public function rules()

	{

		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('id, fileName, description, extraId', 'required'),

			array('id', 'numerical', 'integerOnly'=>true),

			array('fileName, description', 'length', 'max'=>50),

			array('extraId', 'length', 'max'=>10),

			// The following rule is used by search().

			// Please remove those attributes that should not be searched.

			array('id, fileName, description, extraId', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

		);

	}


	/**

	 * @return array customized attribute labels (name=>label)

	 */

	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'fileName' => 'File Name',

			'description' => 'Description',

			'extraId' => 'Extra',

		);

	}


	/**

	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

	 */

	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;


		$criteria->compare('id',$this->id);

		$criteria->compare('fileName',$this->fileName,true);

		$criteria->compare('description',$this->description,true);

		$criteria->compare('extraId',$this->extraId,true);


		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

}



And My Index page path is view/xupload/index.php and code is




<?php

$this->widget('xupload.XUpload', array(

		'url' => Yii::app()->createUrl("xupload/upload"),

		'model' => $model,

		'attribute' => 'file',

		'multiple' => true,

));

?>



Take a look at the server response in your network tab

Well… your model (xupload) doesnt really have an ‘url’ attribute, it only has id, fileName, description and extraId, the default action (XUploadAction), its only there as an example of the action that should handle the file uploads, and it assumes the use of an XUploadForm which has the url attribute defined.

You are supposed to write your own upload action, with the logic that suits your task.

Just started to use this great extension in my project yesterday. I have no problems with uploads, but am missing how to display and manage existing files in the target directory. I can see a download template hence there is obviously a convenient way to get the file list. Am wanting to use not just to upload but manage files - common requirement for sure.

Whats confusing me is the only place I can see so far to set the destination directory is within the upload action set by url paramater for the xupload widget. Am digging deeper but would love a little timely help of convenient.

Cheers

Andrew

Good luck!

Hi Asgaroth

Am investigating that now. Hope it is alright to ask this here - is there a suitable paypal donation to this project that would help to get your help with this?

There is not, sadly.

Apart from you there have been some people asking this, so after your question I added a task to my TODOs, and will be writing a wiki, however I can’t give you an ETA, this is something I personally have never required, so id have to find some free time to check it out, test it, document and then actually write the wiki.

very sad :-[ , never mind, at least your reply is indicating to me that it isn’t something simple that I am overlooking, so am hacking my way into now. Will post any solution I might come up with that might might be a starting point for your undoubtedly superior way.

Incidentally I am also not seeing how to make use of the download template - I see where both upload and download are rendered but not grasping without tracing how there can be a download widget without a directory to take files from?

Cheers

Andrew

the upload template is rendered as soon as you select the file. before uploading.

and the download template is used after the upload has happened allowing you to download, or delete, the files you just uploaded.

That explains. Am part way thru using the demo indicated on your suggested previous link as a starting point. Will return to this later today.

Thanks heaps for your help.

Cheers

Andrew

Hello,

and thanks for implement this jquery plugin to Yii.

im having some troubles, but when i upload an image, there are no "animations" (progressbar) or thumb generated, the file is uploaded ok, i mean, everything works ok, but no that, is this normal??

thank you, and sorry my bad english …

does the included demo works?

Forget this … sorry. was my problem, outside files where not loaded because i’m working under SSL and temote files (tmpl.min.js) was being blocket.

thanks for your reply anyway!!

i’ll make a fork and try to help.

Great! any contribution is very welcome!

Hi Asgaroth,

Thank you for this beautiful extension. I’m having an issue where after uploading the file the value is not getting updated in the DB field. I read as much post I found in this forum and exhausted. I really need your help as I have run out of all options.

My View file

<?php $form=$this->beginWidget(‘CActiveForm’, array(

    'id'=&gt;'assessment-form',


    'enableAjaxValidation'=&gt;false,

));

echo $form->hiddenField($model,‘File’,array(‘size’=>60,‘maxlength’=>255));

?>

<?php $this->endWidget(); ?>

<?php

$this->widget(‘xupload.XUpload’, array(

                'url' =&gt; Yii::app()-&gt;createUrl(&quot;site/upload&quot;),


                'model' =&gt; &#036;xuploadform,


                'attribute' =&gt; 'file',


                'multiple' =&gt; true,


                //'formView' =&gt; 'application.views.user._form',


                'uploadTemplate' =&gt; '#template-upload',


                'options' =&gt; array(


                'sequentialUploads' =&gt; true,


                'acceptFileTypes' =&gt; 'js:/(&#092;.|&#092;/)(CSV|ZIP)&#036;/i',


                'completed' =&gt; 'js:function (event, files, index, xhr, handler, callBack) {


                    &#036;(&quot;#Assessment_File&quot;).val(&#092;'&#092;'+handler.response.name + &#092;'&#092;' );


                    }'


                ),

));

?>

<div class="Assessment">

<?php

echo $out1;

?>

</div>

============

My controller file is as per your documentation,

    public function actions()


    {


            Yii::import(&quot;xupload.models.XUploadForm&quot;);


            return array(


                    'upload'=&gt;array(


                    'class'=&gt;'xupload.actions.XUploadAction',


                    'path' =&gt;Yii::app() -&gt; getBasePath() . &quot;/&#46;&#46;/uploads/&quot;,


                    'publicPath' =&gt; Yii::app() -&gt; getBaseUrl() . &quot;/uploads&quot;,


                    'subfolderVar'=&gt;'parent_id',


                    ),


            );


    }





   public function actionIndex() {


            &#036;this-&gt;layout='column3';


            Yii::import(&quot;xupload.models.XUploadForm&quot;);


            &#036;model = new Assessment();


            &#036;xuploadform = new XUploadForm;


            &#036;template = 'application.views.assessment.index';


            &#036;user = Yii::app()-&gt;user-&gt;name;


            &#036;_userData = User::model()-&gt;with('assessment')-&gt;find(&quot;username=?&quot;,array(&#036;user));


            &#036;criteria=new CDbCriteria;


            &#036;criteria = &#036;criteria-&gt;compare('user_id',&#036;_userData-&gt;id);


            &#036;dataProvider=new CActiveDataProvider('Assessment', array('criteria' =&gt; &#036;criteria));


            &#036;out1 = &#036;this-&gt;renderPartial(&#036;template, array('dataProvider' =&gt; &#036;dataProvider),true);


            #&#036;this-&gt;render('adjacencyGrid',array('out1'=&gt;&#036;out1));


            &#036;this -&gt; render('index', array('model' =&gt; &#036;model, 'out1' =&gt; &#036;out1, 'xuploadform' =&gt; &#036;xuploadform));


    }

===

It just uses another view to render data where first half is Xupload and rest is populated with Assessment model filtered data,

Assessment View:


<h1>Assessments</h1>

<?php

$this->widget(‘zii.widgets.jui.CJuiButton’, array(

'name'=&gt;'Data',


'caption'=&gt;'Data',


'buttonType' =&gt; 'link',


//'url' =&gt; array('//JobsThroughPut/index'), 


'id' =&gt; 'Data-id',

));

$this->widget(‘zii.widgets.jui.CJuiButton’, array(

'name'=&gt;'Reports',


'caption'=&gt;'Reports',


'buttonType' =&gt; 'link',


//'url' =&gt; array('//JobsThroughPut/index'),


    'id'=&gt;'btn-link',

));

$this->widget(‘zii.widgets.grid.CGridView’, array(

    'id'=&gt;'assessment-grid',


    'dataProvider'=&gt;&#036;dataProvider,


    'columns'=&gt;array(


           'id' =&gt; array('name' =&gt; '', 'type'=&gt; 'raw', 'value'=&gt;'CHtml::checkBox(&quot;checkbox-id&quot;,&#036;checked=false,array(&quot;id&quot;=&gt;&#036;data-&gt;id, &quot;class&quot;=&gt;&quot;my-checkboxes&quot;))'),


    /*        'user_id', */


            'fromid',


            'cc',


            'created_date',


            'lastupdate',


            'modeType',


            'File',


            'Status',


    ),

));

?>

<script type="text/javascript">

$(document).ready(function(){

    &#036;(&quot;.my-checkboxes&quot;).bind('click', function(){


            var id = &#036;(this).attr('id');





            &#036;(&quot;#btn-link&quot;).attr('href', '&#46;&#46;/jobsPerHour/getchart/ass_id/'+id); 


            &#036;(&quot;#Data-id&quot;).attr('href', '&#46;&#46;/jobsPerHour/index/ass_id/'+id);


    });

});

</script>

Please help me.

Regards,

Amar.

I’ll try to help you out, but please format your code because this way its really hard to read. use the “insert code snippet” in the post tools.

Hi Asgaroth,

Thanks for your swift response. I’ve added the code snippet,

My site Index file:





<?php $form=$this->beginWidget('CActiveForm', array(

        'id'=>'assessment-form',

        'enableAjaxValidation'=>false,

));

 echo $form->hiddenField($model,'File',array('size'=>60,'maxlength'=>255));

?>

<?php $this->endWidget(); ?>

<?php

$this->widget('xupload.XUpload', array(

                    'url' => Yii::app()->createUrl("site/upload"),

                    'model' => $xuploadform,

                    'attribute' => 'file',

                    'multiple' => true,

                    //'formView' => 'application.views.user._form',

                    'uploadTemplate' => '#template-upload',

                    'options' => array(

                    'sequentialUploads' => true,

                    'acceptFileTypes' => 'js:/(\.|\/)(CSV|ZIP)$/i',

                    'completed' => 'js:function (event, files, index, xhr, handler, callBack) {

                        $("#Assessment_File").val(\'\'+handler.response.name + \'\' );

                        }'

                    ),

));

?>


<div class="Assessment">

<?php

echo $out1;

?>

</div>

~               



  1. My Site controller:




        public function actions()

        {

                Yii::import("xupload.models.XUploadForm");

                return array(

                        'upload'=>array(

                        'class'=>'xupload.actions.XUploadAction',

                        'path' =>Yii::app() -> getBasePath() . "/../uploads/",

                        'publicPath' => Yii::app() -> getBaseUrl() . "/uploads",

                        'subfolderVar'=>'parent_id',

                        ),

                );

        }




  1. It just uses another view to render data where first half is Xupload and rest is populated with Assessment model filtered data,

Assessment Index:





h1>Assessments</h1>


<?php


$this->widget('zii.widgets.jui.CJuiButton', array(

    'name'=>'Data',

    'caption'=>'Data',

    'buttonType' => 'link',

    //'url' => array('//JobsThroughPut/index'), 

    'id' => 'Data-id',

));


$this->widget('zii.widgets.jui.CJuiButton', array(

    'name'=>'Reports',

    'caption'=>'Reports',

    'buttonType' => 'link',

    //'url' => array('//JobsThroughPut/index'),

        'id'=>'btn-link',

));


$this->widget('zii.widgets.grid.CGridView', array(

        'id'=>'assessment-grid',

        'dataProvider'=>$dataProvider,

        'columns'=>array(

               'id' => array('name' => '', 'type'=> 'raw', 'value'=>'CHtml::checkBox("checkbox-id",$checked=false,array("id"=>$data->id, "class"=>"my-checkboxes"))'),

        /*        'user_id', */

                'fromid',

                'cc',

                'created_date',

                'lastupdate',

                'modeType',

                'File',

                'Status',

        ),

));

?>


<script type="text/javascript">


$(document).ready(function(){

        $(".my-checkboxes").bind('click', function(){

                var id = $(this).attr('id'); 

                $("#btn-link").attr('href', '../jobsPerHour/getchart/ass_id/'+id); 

                $("#Data-id").attr('href', '../jobsPerHour/index/ass_id/'+id);

        });

});

</script>



Thanks again for all your help.

Regards,

Amar.