2015-04-27 69 views
0

上傳時使用codeignitor我的形象沒有得到插入上傳我的形象是不會得到插入:同時使用codeignitor

function add_newblog() 
    { 
      $sess_id = $this->session->userdata('id'); 
      $result['query'] = $this->login_model->profile($sess_id); 
      foreach($result['query'] as $row) 
       { 
       $email = $row->blogger_email; 
       $url = $row->blogger_url; 
       $author = $row->blogger_name; 
      if ($this->input->post('submit')) { 

      $config['upload_path'] = './uploads/'; 
      $config['allowed_types'] = 'gif|jpg|png'; 
      $config['max_size'] = '0'; 
      $config['max_width'] = '0'; 
      $config['max_height'] = '0'; 

      $this->load->library('upload', $config); 

      if (!$this->upload->do_upload()) { 
       $error = array('error' => $this->upload->display_errors()); 
       $media = 'No Image Uploaded'; 

      $title = $this->input->post("title"); 
      $category = $this->input->post('category'); 
      $content = $this->input->post('content'); 
        $this->blog_model->add_newblog($sess_id,$title,$category,$content,$media,$email,$url,$author); 

        $this->session->set_flashdata('valid', 'Blog Created without Image'); 
        redirect('content_writer/add_blog'); 
       } 
      else { 
       $data = array('upload_data' => $this->upload->data()); 
       $data = $this->upload->data(); 

       $media = $data['file_name']; 
       $title = $this->input->post("title"); 
       $category = $this->input->post('category'); 
       $content = $this->input->post('content'); 

        $this->blog_model->add_newblog($sess_id,$title,$category,$content,$media,$email,$url,$author); 
        $this->session->set_flashdata('valid', 'Blog Created'); 
        redirect('content_writer/add_blog'); 
       } 

      } 
      else{ 
       $this->session->set_flashdata('invalid', 'Invalid'); 
        redirect('content_writer/add_blog'); 
      } 
      } 
     } 

的其他條件總是工作。圖像名稱不會保存在圖像路徑中。

+1

未插入意味着不插入數據庫或不上傳夾? – Saty

+0

@saty無論...每當我嘗試通過此上傳字段插入圖像或媒體(查看頁面查詢 -

)它總是工作沒有上傳文件條件... – Nayanz

+0

總是它顯示的價值$媒體=沒有圖像已上傳 – Nayanz

回答

1

的問題是在這裏在這一行

$config['upload_path'] = './uploads/'; 

改用

$config['upload_path'] = 'uploads/<folder name>'; 

或櫃面要直接保存圖像上傳夾,只是用

$config['upload_path'] = 'uploads/'; 

以及使你的你在veiw部分rm打開form_open_multipart() 希望這將解決您的問題

+0

@ karvin.developer謝謝.. – Nayanz

+0

您的歡迎 - @ Nayanz –

0

設置你的max_size,MAX_WIDTH和MAX_HEIGHT。這將在下面的例子。

$config['max_size'] = '3000'; 
$config['max_width'] = '1500'; 
$config['max_height'] = '1500'; 
+0

我看@salty先說了,對不起 –

+0

如果你給個建議把評論沒有給出答案 – Saty

+0

我不能,還沒有聲望呢:/ @saty –

0

您還沒有通過$ this-> upload-> do_upload()方法中的圖像名稱。

使用

輸入類型= '文件' NAME = myDoc

$這個 - > upload-> do_upload( 「myDoc」)