2017-04-18 238 views
1

我試圖讓用戶配置文件和笨新增個人資料相片的功能,我的simpy複製粘貼在文檔中提供的文件上傳代碼,但它顯示error.my視圖文件是錯誤在上傳圖像文件

<?php echo form_open_multipart('upload/do_upload');?> 

<input type="file" name="userfile" size="20" /> 

<br /><br /> 

<input type="submit" value="upload" /> 

我控制器

<?php 

class Upload extends CI_Controller { 

    public function __construct() 
    { 
      parent::__construct(); 
      $this->load->helper(array('form', 'url')); 
      $this->load->library('upload'); 
    } 



    public function do_upload() 
    { 
      $config['upload_path']   = './images/'; 
      $config['allowed_types']  = 'gif|jpg|jpeg|png'; 
      $config['max_size']    = 100; 
      $config['max_width']   = 1024; 
      $config['max_height']   = 768; 

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

      if (! $this->upload->do_upload('userfile')) 
      { 
        $error = array('error' => $this->upload->display_errors()); 

        echo'not happening'; 
      } 
      else 
      { 
        $data = array('upload_data' => $this->upload->data()); 

        $this->load->view('upload_success', $data); 
      } 
    } 
} 
?> 

它顯示在這裏的錯誤,我的意思是呼應「沒有發生」,這意味着它不uploading.if有人能請幫助我,這將是巨大的。

+0

什麼錯誤是它展示? –

+0

[爲什麼「有人能幫助我嗎?」不是一個實際的問題?(http://meta.stackoverflow.com/q/284236) –

+0

是否web服務器對該文件夾的寫權限,它被上傳到?大概有90%的機會它不,這是相關 – gabe3886

回答

1

爲什麼不是你檢查什麼是確切的錯誤?我剛剛更新了代碼,以跟蹤codeigniter返回的確切錯誤。

if (! $this->upload->do_upload('userfile')) 
{ 
    $error = array('error' => $this->upload->display_errors()); 
    echo '<pre>'; 
    print_r($this->upload->display_errors()); 
} 
0

您已經加載庫兩次有時候我發現會造成一些問題,你已經把一個在構造函數中,一個在功能

嘗試像下面,並在__constructor使用$this->upload->initialize($config);在功能和加載庫。

https://www.codeigniter.com/user_guide/libraries/file_uploading.html#preferences

<?php 

class Upload extends CI_Controller { 

    public function __construct() 
    { 
      parent::__construct(); 
      $this->load->helper(array('form', 'url')); 
      $this->load->library('upload'); 
    } 

    public function do_upload() 
    { 
      $config['upload_path'] = './images/'; 
      $config['allowed_types'] = 'gif|jpg|jpeg|png'; 
      $config['max_size'] = 5000; 
      $config['max_width'] = 0; 
      $config['max_height'] = 0; 

      $this->upload->initialize($config); 

      if (! $this->upload->do_upload('userfile')) 
      { 
        $error = array('error' => $this->upload->display_errors()); 

        echo'not happening'; 
      } 
      else 
      { 
        $data = array('upload_data' => $this->upload->data()); 

        $this->load->view('upload_success', $data); 
      } 
    } 
} 

注不需要關閉笨控制器和型號?>爲 說,在用戶指南

application 

// Where you upload images to 

images 

system 

index.php