Ajaxsubmitbutton File Field Undefined Index

I want to send a file to my ajax Controller, but it sais "Undefined index: download_file"

I googled around for 2 hours but i cant understand the problem behind.

My View:




<? $form = $this->beginWidget('CActiveForm', array('id' => 'input-form-adddownload', 'htmlOptions' => array('enctype' => 'multipart/form-data'))); ?>

<input id="fileUploader" type="file" name="download_file" value="">

            <?=

            CHtml::ajaxSubmitButton(

                    'Do it', array('ajax/SaveNewDownload'), array(

                'type' => 'post',

                'beforeSend' => 'function(){$("#error_download").html("loading...");}',

                'success' => 'js:function(msg){$("#error_download").html(msg);}',

                    ), array('class' => 'ans_submit_button', 'id' => 'btn_new')

            );

            ?>

        <td><span id="error_download"></span></td>


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




Ajax Controller:




    public function actionSaveNewDownload() {

        print_r($_FILES["download_file"]); 

           echo "test string";

    }



when i change the file field to text and test something to output then everything works great.

i want to store a file in my ajax method.

well i could build a big workaround with own javascript code and everything but i dont understand the main problem here, why this seems not to be possible with the ajaxsubmitbutton?

thx

you not sending any data to server, how do expect it to be there


<?php  

CHtml::ajaxSubmitButton(

                    'Do it', array('ajax/SaveNewDownload'), array(

                'type' => 'post',

'data'=>'js:jQuery(this).parents("form").serialize(), // add this in your code

                'beforeSend' => 'function(){$("#error_download").html("loading...");}',

                'success' => 'js:function(msg){$("#error_download").html(msg);}',

                    ), array('class' => 'ans_submit_button', 'id' => 'btn_new')

            );

            ?>




EDIT: I forgot you cannot upload file thru ajax, you can hack it and make to upload instead of reinventing the wheel look for a jquery plugin

Files aren’t sent in ajax requests. There are plenty of prebuilt solutions that you can use to abstract this away though. Here’s a Yii extension you could try:

http://www.yiiframework.com/extension/eajaxupload