可以同时上传图像或任何其他文档(pdf /单词/文本)


Can Image or any other document(pdf/word/text) upload as a same time?

我正在尝试以一种形式上传图像和其他文档,如PDF/文档/文本等,但一次我只能上传一件事,我可以在一个表格中使用codeIgniter上传相同的内容吗?

您可以使用单个表单,但控制器的逻辑必须不同才能接受多个文件

$this->load->library('upload', $config); //initial load of the upload library
$this->upload->do_upload($field_name1); //uploading first file
[...]
$this->upload->initialize($config); //re-initializing the config
$this->upload->do_upload($field_name2); //uploading second file

如果要上传更多文件,则可能需要将逻辑置于循环中。

是的...我们可以借助代码点火器功能同时上传不同的格式。

首先为一种格式初始化一个配置,例如:

$config['upload_path'] = $upload_path;
$config['file_name'] = rand(10,99);
$config['allowed_types'] = 'gif|jpg|png';
$this->load->library('upload', $config);
$this->upload->initialize($config);               //initialize upload config
$this->upload->do_upload($filename)

上传一个格式化文件时,重置配置

unset($config);
$this->image_lib->clear();

之后,您可以初始化另一种格式的另一个配置。