我过去遇到过我认为类似的事情。
如果您正在循环浏览上传的文件,不同$config
的文件不同,则需要在每次迭代之间初始化上传类:
$this->upload->initialize( $config );
你有 pastebin 或一些代码示例吗?
这是我在早期项目中所做的,用于根据文件类型处理更改 $config :
if( $_FILES ) { $this->load->library('upload');
foreach ( $_FILES as $key => $value )
{
$file_type = ( $key == 'image' ) ? 'image' : 'document';
if( ! empty( $value['name'] ))
{
$config = array(
'upload_path' => './uploads/materials/' . strtolower($material['code']) . '/',
'allowed_types' => ($file_type == 'image') ? 'jpg|jpeg|png' : 'jpg|jpeg|png|pdf',
'max_size' => 1024 * 10,
'max_width' => 19200,
'max_height' => 12800,
'overwrite' => TRUE,
);
// ------------------------------------------------------------------------
// Here is the key idea: You need to initialize each time you change the $config
// ------------------------------------------------------------------------
$this->upload->initialize( $config );
if( $this->upload->do_upload( $key ))
{
//Success! Files are all uploaded.
$uploaded = $this->upload->data();
$data['file_data'] = array(
'parent_id' => $data['material']->id,
'filename' => $uploaded['file_name'],
'filename_original' => $uploaded['client_name'],
'type' => $file_type,
'location' => $config['upload_path'],
'description' => '',
);
// Add the file details to the database
$this->material->add_material_file( $data );
}
else
{
// ERROR! Something went wrong... alert the user.
$errors = $this->upload->display_errors();
$this->session->set_flashdata( 'flashError', $errors );
}
}
}
}