2013-02-20 95 views
0

由於各種原因,我不能使用正常的方式來構建表單,所以我稍微改變了一些位。 對於正常的發佈行爲這是工作很好,但是當我嘗試上傳文件時,一切都出錯了。Yii和自定義文件上傳(使用jasny引導)

我把這個作爲表單,上傳了Jasny文件。

<?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(); ?> 

至於說,所有的數據後工作正常,但是當我來到這個文件輸入我得到了$_POST['RssPlanStyle']['tab_icon']$_FILES['RssPlanStyle']['tab_icon']是空的。 這是我的上傳功能atm。

公共職能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"; 
} 

}

所以我得到的部分echo 'new image',也顯示了echo 'leeg'。我究竟做錯了什麼?

什麼將正確的方式來處理上傳。

+0

我不明白您正在使用哪個文件上傳器。你在使用http://www.yiiframework.com/doc/api/1.1/CMultiFileUpload嗎? – 2013-02-20 12:52:49

+0

目前我不使用任何,我剛剛創建一個與asny文件上傳擴展的表單。其中基本填充'' – Augus 2013-02-20 13:17:02

+0

我明白了。我對Jasny不熟悉。這有幫助嗎? http://stackoverflow.com/questions/13118407/how-to-get-file-location-using-jasny-file-upload – 2013-02-20 17:13:40

回答