如何在codeigniter中上传多个/多个图像[重复]
Posted
技术标签:
【中文标题】如何在codeigniter中上传多个/多个图像[重复]【英文标题】:How to Upload Multiple/many image in codeigniter [duplicate] 【发布时间】:2018-08-01 02:17:53 【问题描述】:我的源代码有问题,当输入许多图像和不同的图像/上传文件时,得到的结果是相同的图像。怎么解决啊,求大神们帮忙
控制器
public function tambahprogress()
$this->load->helper('url','form');
$this->load->library('form_validation');
$this->form_validation->set_rules('keterangan','keterangan','trim|required');
$this->load->model('progress/progress_model');
if ($this->form_validation->run()==FALSE)
$data['pekerjaan']=$this->progress_model->combopekerjaan();
$data['pekerja']=$this->progress_model->combopekerja();
$this->load->view('progress/tambahprogress', $data);
else
$config['upload_path'] = './assets/upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000000000;
$config['max_width'] = 10240;
$config['max_height'] = 7680;
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
$error = array('error' => $this->upload->display_errors());
$this->load->view('progress/tambahprogress',$error);
else
$image_data = $this->upload->data();
$configer = array (
'image_library'=>'gd2',
'source_image'=>$image_data['full_path'],
'width'=>800,
'height'=>600,
);
$this->load->library('image_lib',$config);
$this->image_lib->clear();
$this->image_lib->initialize($configer);
$this->image_lib->resize();
$this->progress_model->insertProgress();
$this->load->view('progress/tambahprogresssukses');
型号
public function insertProgress()
$object = array
(
'id_progress' =>$this->input->post('id_progress'), 'no_spk' =>$this->input->post('no_spk'),'progress' =>$this->input->post('progress'), 'keterangan' =>$this->input->post('keterangan'), 'gambar'=>$this->upload->data('file_name'), 'gambar2'=>$this->upload->data('file_name'), 'gambar3'=>$this->upload->data('file_name'), 'id_pekerja' =>$this->input->post('id_pekerja')
);
$this->db->insert('progress',$object);
查看(输入过程)
<div class="form-group">
<label for="">Masukkan Gambar</label>
<<input type="file" name="userfile" size="20"/>
</div>
<div class="form-group">
<input type="file" name="userfile" size="20"/>
</div>
<div class="form-group">
<input type="file" name="userfile" size="20"/>
</div>
结果是相同的图像,但是当我输入数据时,我输入了不同的图像,请帮助我
【问题讨论】:
【参考方案1】: $config['upload_path'] = PATH; //add path according to your requirements
$config['allowed_types'] = 'jpg|jpeg|png';
$config['overwrite'] = false; //OR true
$config['max_size'] = '100000'; //You can change it
//add more configuration according to your requirements
$this->load->library('upload');
$files = $_FILES;
$number_of_files = count($_FILES['pic']['name']); //"pic" is name of FILE input
//images name will be details0, details1, details2 and soo on.
$errors = 0;
for ($i = 0; $i < $number_of_files; $i++)
$_FILES['pic']['name'] = "details" . $i . ".jpg"; //If you want to change the name of images change "details" with your require name
$_FILES['pic']['type'] = $files['pic']['type'][$i];
$_FILES['pic']['tmp_name'] = $files['pic']['tmp_name'][$i];
$_FILES['pic']['error'] = $files['pic']['error'][$i];
$_FILES['pic']['size'] = $files['pic']['size'][$i];
$this->upload->initialize($config);
if (!$this->upload->do_upload("pic"))
$errors++;
if ($errors > 0)
echo $errors . "File(s) could not be uploaded";
【讨论】:
如何查看?对吗? 使用这个选择多张图片 图片选择 这只是一三个,像图片选择 图片选择 图片选择 上传 3 张图片? 您只能使用此代码选择您的三张照片。兄弟只加一次 哦,我明白了,模型怎么样?对不对? @DanishAli以上是关于如何在codeigniter中上传多个/多个图像[重复]的主要内容,如果未能解决你的问题,请参考以下文章