0

For various reasons I can't use the normal way to build forms so i slightly changed some bits. For normal post actions this is working great but when i try to upload files everything goes wrong.

I got this as form, with the Jasny file upload.

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'plan_style_form_'.$data->id,
    'enableAjaxValidation'=>false,
    'htmlOptions' => array(
        'enctype' => 'multipart/form-data',
    ),

)); ?>

........
                        <div class="fileupload fileupload-exists" data-provides="fileupload" data-name="RssPlanStyle[tab_icon]">
                            <div class="fileupload-new thumbnail" style="width: 111px; height: 74px;"><img src="http://www.placehold.it/200x150/EFEFEF/AAAAAA&text=no+image" /></div>
                            <div class="fileupload-preview fileupload-exists thumbnail" style="width: 111px; height: 74px;"><img src="../images/tab_images/<?php echo $data->RssPlanStyle->tab_icon ?>"></div>
                                <div class="plan_tab_custom_title plan_tab_example_title_<?php echo Chtml::encode($data->RssPlanStyle->id); ?>">
                                    <?php echo Chtml::encode($data->RssPlanStyle->titel_tab); ?>
                                </div><!-- .plan_tab_custom_title -->
                        <div>
                        <div class="span6">
                        <label>Tab icoon</label>
                        <span class="btn btn-file"><span class="fileupload-new">Selecteer Afbeelding</span><span class="fileupload-exists">Verander Afbeelding</span><input type="file" /></span>
                        <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Verwijder Afbeelding</a>
                        </div></div>
.......
                <?php echo CHtml::ajaxSubmitButton(
                    'Opslaan',
                    array('rssPlanStyle/updateStyle'),
                    array('update'=>'#result-style-'.$data['id']),
                    array('class'=>'btn btn-success', 'style'=>'float:right; margin-bottom:20px;')
                ); ?>
.........
<?php $this->endWidget(); ?>

As said all the post data works fine, but when i comes to this file input i do get the $_POST['RssPlanStyle']['tab_icon'] but the $_FILES['RssPlanStyle']['tab_icon'] is empty. This is my upload function atm.

public function actionUpdateStyle(){

// tab_icon
if(isset($_POST['RssPlanStyle']['tab_icon'])) {
// Als afbeelding is veranderd
    if ($_POST['RssPlanStyle']['tab_icon'] == '') {
    // Als afbeelding is verwijderd
        echo 'image verwijderd';
    } else {
    // Als er een nieuwe afbeelding is
        if(empty($_FILES['RssPlanStyle']['tab_icon'])){
            echo 'leeg';
        }

        echo 'new image';

    }
} else {
// Als afbeelding niet is veranderd
    echo "niks veranderd";
}

}

So i am getting to the part echo 'new image', but also the echo 'leeg' is shown. What am i doing wrong?

And what would the correct way to handle the upload.

Arnold Daniels
  • 16,516
  • 4
  • 53
  • 82
Augus
  • 495
  • 1
  • 8
  • 24
  • I do not understand which file uploader you are using. Are you using http://www.yiiframework.com/doc/api/1.1/CMultiFileUpload ? – Ivo Renkema Feb 20 '13 at 12:52
  • At the moment i don't use any, i just created an form with with the asny file upload extension. Which basicly fills in an `` – Augus Feb 20 '13 at 13:17
  • I see. I am not familiar with Jasny. Does this help any? http://stackoverflow.com/questions/13118407/how-to-get-file-location-using-jasny-file-upload – Ivo Renkema Feb 20 '13 at 17:13

1 Answers1

0
    if (yii::app()->request->isPostRequest) {

            $model = new ModelForm;
            $model->file=CUploadedFile::getInstance($model,'RssPlanStyle');

            if ($model->file != NULL){
                echo 'new image';
            }else{
                echo 'no image';
            }
    }

you can use getInstances() to handle multi upload. please see http://www.yiiframework.com/doc/api/1.1/CUploadedFile#getInstance-detail

rizarc
  • 1
  • 1
  • 1