2014-09-02 188 views
0
$config['upload_path'] = './content/'; 
     $config['allowed_types'] = 'gif|jpg|png|jpeg'; 
     $this->load->library('MY_Upload'); 
     $this->upload->initialize($config); 
     $this->upload->initialize(array(
     "file_name"  => array("file_1.jpg", "file_2.jpg", "file_3.jpg"), 
     "upload_path" => "./content/" 
    )); 

     if($this->upload->do_multi_upload("userfile")){ 
      print_r($this->upload->get_multi_upload_data()); 
     } 

我已將此代碼用於多次上傳,但不工作,致命錯誤:類'CI_Upload'未找到,錯誤屬於此類型。致命錯誤:未找到類'CI_Upload'

+0

你的代碼,你不應該裝載庫' MY_Upload'這種方式,假設你想從'MY_Upload'自定義上傳庫擴展'CI_Upload',你應該用這種方式加載'$ this-> load-> library('upload');''CI' MY_Upload'的自動優先級 – Girish 2014-09-02 06:43:16

回答

1

擴展本機庫

如果你需要做的就是添加一些功能,以現有的庫 - 也許增加一個或兩個功能 - 那麼它重寫自己更換整個庫。在這種情況下,最好簡單地擴展這個類。擴展一個類幾乎相同,除了兩個例外替換類:

The class declaration must extend the parent class. 
Your new class name and filename must be prefixed with MY_ (this item is configurable. See below.). 

例如,擴展一個本地電子郵件類,你應該建立一個應用程序/庫/ MY_Email.php文件,並聲明你的類搭配:

class MY_Upload extends CI_Upload { 

    } 

注意:如果你需要在類中使用構造函數確保您擴展父類的構造:

class MY_Upload extends CI_Upload { 

      public function __construct() 
      { 
       parent::__construct(); 
      } 
public function some_function() 
{ 

} 
     } 

加載你的子類

要加載您的子類,您將使用通常使用的標準語法。請勿包含您的前綴。例如,加載上面的例子中,它擴展了電子郵件類中,將使用:

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

一旦加載即可正常的類要擴展將要使用的類變量。在電子郵件類的情況下,所有呼叫都將使用:

$this->upload->some_function(); 

我想你理解擴展本機庫

你可以改變這樣的

$config['upload_path'] = './content/'; 
     $config['allowed_types'] = 'gif|jpg|png|jpeg'; 
/************* i am changing only loading class only *********************/ 
     $this->load->library('upload'); 

     $this->upload->initialize($config); 
     $this->upload->initialize(array(
     "file_name"  => array("file_1.jpg", "file_2.jpg", "file_3.jpg"), 
     "upload_path" => "./content/" 
    )); 

     if($this->upload->do_multi_upload("userfile")){ 
      print_r($this->upload->get_multi_upload_data()); 
     }