我能够获得一张图片的路径但是如何获取第二张图片的路径是我的代码:
查看:
echo "<div class='form-group'>";
echo form_label('Brand Logo');
$img=array('name'=>'brand_logo','class'=>'form-control');
echo form_upload($img);
echo "</div>";
echo "<div class='form-group'>";
echo form_label('Brand Banner');
$banner=array('name'=>'banner','class'=>'form-control');
echo form_upload($banner);
echo "</div>";
控制器:
function upload_brand()
{
$rules=['upload_path'=>'./assets/brand_images','allowed_types'=>'gif|jpg|png|jpeg'];
$this->load->library('upload',$rules);
if($this->upload->do_upload('brand_logo') && $this->upload->do_upload('banner'))
{
$data=$this->upload->data();
print_r($data);
}
else
{
$upload_error=$this->upload->display_errors();
$this->load->view('admin/create_brand',compact('upload_error'));
}
}
答案 0 :(得分:0)
尝试使用codeigniter上传多个文件。 https://github.com/stvnthomas/CodeIgniter-Multi-Upload
答案 1 :(得分:0)
你可以通过两种方式做到:
复制逻辑:
function upload_brand() {
$rules = ['upload_path' => './assets/brand_images', 'allowed_types' => 'gif|jpg|png|jpeg'];
$this->load->library('upload', $rules);
if ($this->upload->do_upload('brand_logo')) {
$data1 = $this->upload->data();
//print_r($data1);
} else {
$upload_error = $this->upload->display_errors();
$this->load->view('admin/create_brand', compact('upload_error'));
exit;
}
if ($this->upload->do_upload('banner')) {
$data2 = $this->upload->data();
print_r($data1);
print_r($data2);
} else {
$upload_error = $this->upload->display_errors();
$this->load->view('admin/create_brand', compact('upload_error'));
exit;
}
}
FOREACH:
function upload_brand() {
$rules = ['upload_path' => './assets/brand_images', 'allowed_types' => 'gif|jpg|png|jpeg'];
$this->load->library('upload', $rules);
$uploads = array('brand_logo', 'banner');
$files = array();
foreach ($uploads as $fieldname) {
if (!$this->upload->do_upload($fieldname)) {
$upload_error = $this->upload->display_errors();
$this->load->view('admin/create_brand', compact('upload_error'));
exit;
}
$files[] = $this->upload->data();
}
print_r($files);
}