2012-02-15 89 views
0
//uploading product movie or image? 
     if($this->input->post('upload_360') == "Upload") { 
      $config['upload_path'] = './media/images/products/360s'; 
      $config['allowed_types'] = 'swf'; 
      $this->load->library('upload', $config); 
      $this->upload->initialize($config); 
      if (!$this->upload->do_upload('film')) { 
       $this->data['product_error'] = $this->upload->display_errors(); 
       $this->template->build('/admin/products/create', $this->data); 
      } else { 
       $this->data['data_360'] = $this->upload->data(); 
       $this->session->set_userdata(array('360_film' => $this->data['data_360'])); 
       $this->template->build('/admin/products/create', $this->data); 
      } 
      $this->session->set_userdata(array('advantages' => $this->input->post('product_advantages'))); 
      $this->data['session_advantages'] = $this->session->userdata('advantages'); 
     } 
     //upload the product image, if successful the user will be 
     //notified if the image is too high or wide, and will be offered, 
     //the chance to crop the image. All cropping takes place in the media 
     //controller. 
     if($this->input->post('product_image') == "Upload") { 
      $config['upload_path'] = './media/images/products/'; 
      $config['allowed_types'] = 'gif|jpg|jpeg|png'; 
      $this->load->library('upload', $config); 
      $this->upload->initialize($config); 
      if (!$this->upload->do_upload('image_upload')) { 
       //die("!"); 
       $this->data['image_error'] = $this->upload->display_errors(); 
       $this->template->build('/admin/products/create', $this->data); 
      } else { 
       $this->data['image_data'] = $this->upload->data(); 
       $this->session->set_userdata(array('image' => $this->data['image_data'])); 
       $this->data['session_image'] = $this->session->userdata('image'); 
       $this->template->build('/admin/products/create', $this->data); 
      } 
      $this->session->set_userdata(array('advantages' => $this->input->post('product_advantages'))); 
      $this->data['session_advantages'] = $this->session->userdata('advantages'); 
     } 

     if($this->input->post('screenshot_upload') == "Upload") { 
      $config['upload_path'] = './media/images/products/360s/screenshots/'; 
      $config['allowed_types'] = 'gif|jpg|jpeg|png'; 
      $this->load->library('upload', $config); 
      $this->upload->initialize($config); 
      if (!$this->upload->do_upload('screenshot')) { 
       //die("!"); 
       $this->data['screenshot_error'] = $this->upload->display_errors(); 
       $this->template->build('/admin/products/create', $this->data); 
      } else { 
       $this->data['screenshot_data'] = $this->upload->data(); 
       $this->session->set_userdata(array('screenshot' => $this->data['screenshot_data'])); 
       $this->data['session_screenshot'] = $this->session->userdata('screenshot'); 
       $this->template->build('/admin/products/create', $this->data); 
      } 
      $this->session->set_userdata(array('advantages' => $this->input->post('product_advantages'))); 
      $this->data['session_advantages'] = $this->session->userdata('advantages'); 
     } 

不設置在我的形式,我讓用戶選擇一個文件,然後點擊上傳按鈕取決於哪個按鈕被點擊被上傳文件並上傳的數據被保存在一個會話。數據會話笨

然後會話用於獲取數據以保存到數據庫,upload_360會話有效,product_image會話正常,但如果我使用if語句(代碼中的第三個),screenshot_upload會話只有數據嘗試並在代碼之外訪問它,那麼會話的那部分是空的?

這是有原因嗎?

+0

是否有錯誤?你使用什麼類型的會話。 Codeigniters cookies,數據庫,本機會話還是會話? – Henesnarfel 2012-02-15 13:26:14

+0

您正在使用哪種瀏覽器? – 2012-02-16 01:33:03

回答

0

爲什麼在將數據插入數據庫之前將數據存儲在會話中?

Cookies只能存儲4KB的數據...

但與if語句(第一個代碼),如果我嘗試screenshot_upload會話只有數據和acccess它的代碼之外,那麼那部分會議是空的?

我不明白你的問題的一部分。你的意思是隻有在使用第三條if聲明時纔有數據?即當只試圖做screenshot_upload而不是product_image或360_upload`?如果是這樣,那可能與Cookie大小限制有關。

而不是

$this->session->set_userdata(array('screenshot' => $this->data['screenshot_data'])); 
$this->data['session_screenshot'] = $this->session->userdata('screenshot'); 

你爲什麼不

$this->uploads_model->insert_screenshot_data($this->data['screenshot_data']);//send screenshot upload_data to model to be inserted into db 
$this->data['screenshot_data'] = $this->data['screenshot_data'];//if you want to pass screenshot upload_data to template/view 

0

看起來你正在設置會話之前發送輸出給用戶(我是從$這個 - >模板 - >打造推斷這一點,這是自定義代碼。)

會議,類似的報頭,任何(ANYTHING)被髮送到輸出後都不能被修改。這是因爲會話本身是在頭部發送的。