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.