php - 如何将 2 张图片上传到两个不同的文件夹(codeginiter)
问题描述
我有这段代码可以将两张图片上传到文件夹'/uploads'
如何将图像 no2 上传到另一个文件夹?
代码
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|svg' ;
$config['max_size'] = 2048;
$this->load->library('upload',$config);
if (! $this->upload->do_upload('userfile') && !$this->upload->do_upload('userfile2') ) {
$errors = array('error' => $this->upload->display_errors());
$post_image= 'noimage.png' ;
$post_image2= 'noimage.png' ;
} else {
$data = array('upload_data' => $this->upload->data()) ;
$post_image= $_FILES['userfile']['name'];
$post_image2= $_FILES['userfile2']['name'];
}
$this->post_model->create_post($post_image,$post_image2);
redirect('../');
解决方案
使用不同的 $config 路径再次加载 lib:
$this->load->library('upload', $config1);
然后上传
$this->load->library('upload', $config2);
另一个使用另一个路径的上传。
你也可以使用initialize($config)
推荐阅读
- jquery - 在 fullcalendar.js 的 fc-day-number 中添加图像在发布后不起作用
- python - 为什么QStackedWidget子页面中的widget btn1只能为QStackedWidget定义信号,而不能为QStackedWidget中的page: deviceTypeSelect定义信号?
- android - React Navigation - 在退出应用程序之前创建确认屏幕
- javascript - Node V10 与 Node V11 中 util.format 的行为
- c++ - 在另一个类中使用 MOCK 函数
- json - 用 JSON 数据填充表
- javascript - 如何使用 Vue JS 创建混合 MPA 和 SPA
- java - 同时使用两个不同的渲染器显示相同的 JTree 实例
- python - 考虑 DBSCAN 的时间
- reactjs - 嵌套反应状态使用钩子在 javascript 表达式上返回未定义和未定义