2017-05-26 100 views
0

我有一個上傳圖像與另一個輸入字段的問題。無法使用codeigniter上傳圖像

這是我的看法

<?php echo form_open_multipart('upload/do_upload');?> 
<input type="file" name="upload" /> 
<input type="submit" value="upload" class="btn" id="upload_submit" name="upload_submit"> 

這是我的控制器

function do_upload() 
{ 
    $file_paths = "C:/Users/admin/Desktop/save_here/"; 
    $this->load->helper('form'); 
    $this->load->helper('url'); 
    $this->load->library('upload'); 
    if($this->input->post('upload_submit')){ 
     if(isset($_FILES["upload"]["tmp_name"])){ 
      $config['upload_path'] = $file_paths; 
      $config['allowed_types'] = 'gif|jpg|png'; 
      $config['max_size']  = '100'; 
      $config['max_width'] = '1024'; 
      $config['max_height'] = '768'; 

      $this->load->library('upload', $config); 
      if (!$this->upload->do_upload('upload')){ 
       $error = array("status"=>"0",'error' => $this->upload->display_errors(),'upload_data'=>''); 
      }else{ 
       $data = array("status"=>"1",'error'=>'','upload_data' => $this->upload->data()); 
      } 
     } 
    } 
} 

我的問題是我不能上傳圖像或沒有圖像已save_here文件被上傳。

+0

避免您的目錄名中有空格。使用類似save_here –

+0

@YadhuBabu仍然不工作 –

+0

任何錯誤消息 –

回答

0

試試這個。您必須使用配置初始化上傳庫

function do_upload() 
{ 
    $file_paths = "C:/Users/admin/Desktop/save_here/"; 
    $this->load->helper('form'); 
    $this->load->helper('url'); 
    $this->load->library('upload'); 
    if($this->input->post('upload_submit')){ 
     if(isset($_FILES["upload"]["tmp_name"])){ 
      $config['upload_path'] = $file_paths; 
      $config['allowed_types'] = 'gif|jpg|png'; 
      $config['max_size']  = '100'; 
      $config['max_width'] = '1024'; 
      $config['max_height'] = '768';   

      // Change This line 
      $this->upload->initialize($config); 
       if (!$this->upload->do_upload('upload')){ 
        $error = array("status"=>"0",'error' => $this->upload->display_errors(),'upload_data'=>''); 
       }else{ 
        $data = array("status"=>"1",'error'=>'','upload_data' => $this->upload->data()); 
       } 
      } 
     } 
} 
0

變化這樣

$ file_paths =您的文件路徑爲 「C:\用戶\ ADMIN \桌面\ save_here \」;

+0

仍然無效 –