2015-01-08 108 views
2

我嘗試將我的Codeigniter Web與uploadify集成。在Chrome甚至IE瀏覽器中都能正常工作,但在Mozilla Firefox中運行我的網頁時出現HTTP 302錯誤。有時候也會顯示「IO Error」,我看過這篇文章:302 and IO uploadify error,但還是不知道我必須做什麼。也許更詳細/明確的指導將是幫助。在PHP Codeigniter中上傳HTTP 302錯誤和IO錯誤

這是我考慮uploadify配置:

$('#shopfile').uploadify({ 
      'debug':false, 
      'auto':true, 
      'swf': '<?= base_url(); ?>file/lib/uploadify/uploadify.swf', 
      'uploader': '<?= base_url(); ?>my_shop/upload_shopheader', 
      'cancelImg': '<?= base_url(); ?>file/lib/uploadify/uploadify-cancel.png', 
      'fileTypeExts':'*.jpg;*.jpeg;*.png;', 
      'fileTypeDesc':'Image Files (.jpg,.jpeg,.png)', 
      'fileSizeLimit':'2MB', 
      'fileObjName':'shopfile', 
      'buttonText':'Select File', 
      'multi':false, 
      'removeCompleted':false, 
      'onUploadError' : function(file, errorCode, errorMsg, errorString) { 
       alert('The file ' + file.name + ' could not be uploaded: ' + errorString); 
       $(".uploadMessageStr").html('<div class="alert alert-danger">The file ' + file.name + ' could not be uploaded: ' + errorString + '</div>'); 
      }, 
      'onUploadSuccess' : function(file, data, response){ 
       //some statement.. 
      } 
     }); 

,這是我的控制器/上傳功能代碼:之前

public function upload_shopheader(){ 
    if (empty($_FILES['shopfile']['name'])) redirect('my_shop/profile'); 

    $config = $this->avatarUploadConfig(); 
    $this->upload->initialize($config); 
    $data = array(); 

    if (!$this->upload->do_upload('shopfile')) { 
     //if upload failed... 
     $upload_error = $this->upload->display_errors(); 
     $data['message'] = "<div class='alert alert-danger'>Upload Failed. ".$upload_error."</div>"; 
    } 
    else { 
     //if upload success... 
    } 

    echo json_encode($data); 
} 

感謝。

回答

2

解決了通過uploadify手動添加會話ID。

添加這uploadify配置在視圖:

'formData' : {'SESSION_ID' : '<?= $this->session->userdata('session_id'); ?>'}, 

和控制器功能的開頭添加以下代碼:

//check session.. 
    $sess_id = $this->input->post('SESSION_ID'); 
    if(!isset($sess_id)){ 
     redirect('to_some/page'); 
    } 
    else{ 
     $this->session->set_userdata(array('session_id' => $sess_id)); 
    }