$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());
}
我已将此代码用于多次上传,但无效,致命错误:Class' CI_Upload'没找到,错误属于这种类型。
答案 0 :(得分: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.).
例如,要扩展本机Email类,您将创建一个名为application / libraries / MY_Email.php的文件,并使用以下命令声明您的类:
class MY_Upload extends CI_Upload {
}
注意:如果需要在类中使用构造函数,请确保扩展父构造函数:
class MY_Upload extends CI_Upload {
public function __construct()
{
parent::__construct();
}
public function some_function()
{
}
}
加载您的子类
要加载子类,您将使用通常使用的标准语法。不要包含你的前缀。例如,要加载上面扩展Email类的示例,您将使用:
$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());
}