0

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

4

2 回答 2

0

是的......我们可以在codeigniter函数的帮助下同时上传不同的格式。

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

$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();

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

于 2014-12-19T10:29:36.513 回答
0

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

$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

如果您有更多文件要上传,您可能希望将您的逻辑置于循环中。

于 2013-10-30T11:48:28.057 回答