Upload an image to two different paths

断了今生、忘了曾经 提交于 2019-11-29 16:21:53

the easiest would be to use ->do_upload() for each of the path you might want to upload to:

$p1='./imgup/web/data_dinamis/';
$p2='./imgup/web/video/';

//create an array of pathes:
$p=array($p1, $p2);

// get length of array
$c=count($p);

// loop through
for ($i=0;$i<$c;$i++){    
  $config['upload_path'] =$p[$i];
  $config['allowed_types'] = '*'; 
  $config['file_name'] = $nama_baru;

  $this->load->library('upload',$config);
  $this->upload->initialize($config);
  $this->upload->do_upload('file');
  $this->upload->display_errors();
}

$berita = array(
   'user_id' =>  $this->session->userdata('user')->user_id,
   'kategori_id' => $this->input->post('kategori_id'),
   'judul' => $this->input->post('judul'),
   'gambar' =>  $nama_baru,
);

note: after $this->load->library('upload',$config); use $this->upload->initialize($config); This is useful if you auto-load the class, see docs here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!