我想使用库中的MY_Upload
在codeigniter版本3中执行multi_upload
图像,但它会错误显示消息:MY_Upload::initialize()
的声明应与{{1}兼容}}。请帮助谢谢
这是我的控制器
CI_Upload::initialize(array $config = Array, $reset = true)
这是我的模特
public function add_pagekage_values(){
if($this->input->post("add")){
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Pagekage Name', 'required|xss_clean|encode_php_tags');
$this->form_validation->set_rules('price', 'Price', 'required|xss_clean|encode_php_tags');
$this->load->library('MY_Upload');
$this->load->library('upload');
$this->upload->initialize(array(
"upload_path" => "./images/pagekage_image/",
'file_name'=>'files',
'allowed_types'=>"gif|png|jpg|png|GIF|PNG|JPG",
'encrypt_name'=>true
));
if($this->upload->do_multi_upload("files")){
$last_data = $this->upload->get_multi_upload_data();
$this->admin_model->add_product_value($last_data);
redirect('admin_controller/pagekage');
}else{
$this->session->set_flashdata(array('already'=>'Please choose file to upload.....!!!'));
redirect('admin_controller/add_pagekage');
}
}
}
答案 0 :(得分:2)
这只是CI3中错误报告级别的差异。您可以通过简单地更改错误消息所暗示的方法签名来使用该库。
由于该方法似乎没有调用父类,因此在扩展类中是否正确实现了第二个参数,这取决于您(尽管您可能需要记录它,以防您或其他人可能需要将来更新您的网站。)
MY_Upload
GitHub <!--Source code-->
MY_Upload
Readme.txt <!--Installation File-->
实施例
您的观点看起来像
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Upload multiple files</h1>
<?php echo form_open_multipart(controller/add_pagekage_values);?>
<p>Upload file(s):</p>
<?php echo form_error('uploadedimages[]'); ?>
<?php echo form_upload('uploadedimages[]','','multiple'); ?>
<br />
<br />
<?php echo form_submit('submit','Upload');?>
<?php echo form_close();?>
</body>
</html>
控制器(上传部分)
if ($this->input->post()) {
$config = array(
'upload_path' => './upload/',
'allowed_types' => 'gif|jpg|png',
'max_size' => '2048'
);
// load Upload library
$this->load->library('upload', $config);
$this->upload->do_upload('uploadedimages');
答案 1 :(得分:0)
我想我找到了解决方案。打开MY_Upload.php
文件夹中存储的application/library
文件。
您的方法应如下所示:
public function initialize($config = array()){
用以下内容替换整行:
public function initialize(array $config = array(), $reset = true){