如何在代码点火器中重置方法



我有一个表单,可以同时上传许多文件和图像。问题是这种方法

$this->upload->display_errors()

每次循环通过这种方法时,都会从上一次循环中节省错误

$error[$i]= "File error: ".$this->upload->display_errors();

例如,如果我上传了两个非法文件,它会显示这个

索引0:不允许文件
索引1:不允许文件不允许

那么我该如何重置此方法呢?ps:我试着重置((函数,但它不起作用

UPDATE这是方法

public function do_upload($product_id)
{
$error = array();
if(isset($_FILES['files']['name'])&&!empty($_FILES['files']['name'][0])):
for ($i=0; $i <count($_FILES['files']['name']) ; $i++) :

$config['upload_path']          = './images/';
$config['allowed_types']        = 'gif|jpg|png';
$config['max_size']             = 1;

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


$_FILES['files[]']['name'] = $_FILES['files']['name'][$i];
$_FILES['files[]']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
$_FILES['files[]']['size'] = $_FILES['files']['size'][$i];
if(!$this->upload->do_upload('files[]')){

$error[$i]= "File name: ". $_FILES['files']['name'][$i] ." ". $this->upload->display_errors() ."<br>";
}else{
$files = $this->upload->data();
$data = array('file_name'=>$files['file_name'],'product_id'=>$product_id,'file_type'=>$files['file_type']);
$this->Files_model->create_file($data);
}


endfor;




endif;
return $error;
//end method
}

我们无法重置$this->upload->do_upload((;

但我们可以像那样重新初始化

// first upload 
$this->config->load('upload');
-- Code to upload Here -- 
// Another file
$this->config->load('upload_other_files');
-- Code to upload Here --

或者你可以为每个文件定义多个配置数组,如下代码:

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->upload->initialize($config);

对于其他文件

$config2['upload_path'] = './uploads/';
$config2['allowed_types'] = 'gif|jpg|png';
$config2['max_size'] = '100';
$config2['max_width'] = '100';
$config2['max_height'] = '100';
$this->load->library('upload', $config2);
// Alternately you can set
$this->upload->initialize($config2);

您可以像这样重置(错误(:

$this->upload->error_msg = [];
...do_upload

相关内容

  • 没有找到相关文章

最新更新