我在表单中上传了3个文件,但是只能在数据库和路径文件夹中保存一个文件。
类Pegawaimagang_model扩展了CI_Model { 私人$ _table =“ pegawaimagang”;
public $id;
public $id_magang;
public $status;
public $username;
public $password;
public $nama;
public $email;
public $notelp;
public $cv;
public $ktp;
public $suratmagang;
public $foto;
public function daftarmagang()
{
$post = $this->input->post();
$this->id = uniqid();
$this->id_magang = $post['id_magang'];
$this->nama = $post["nama"];
$this->email = $post["email"];
$this->notelp = $post["notelp"];
$this->ktp = $post["ktp"];
$this->status = 1;
$this->username = "";
$this->password = "";
$this->suratmagang = $this->_uploadSuratMagang();
$this->foto =$this->_uploadFoto();
$this->cv = $this->_uploadCV();
$this->db->insert($this->_table, $this);
}
private function _uploadFoto()
{
$config['upload_path'] = './upload/pegawaimagang/foto/';
$config['allowed_types'] = 'gif|jpg|png';
$config['file_name'] = $this->id;
$config['overwrite'] = true;
$config['max_size'] = 2048;
$this->load->library('upload', $config);
if ($this->upload->do_upload('foto')) {
return $this->upload->data("file_name");
}
return "default.jpg";
}
private function _uploadCV()
{
$config['upload_path'] = './upload/pegawaimagang/cv/';
$config['allowed_types'] = 'pdf';
$config['file_name'] = $this->id;
$config['overwrite'] = true;
$config['max_size'] = 2048;
$this->load->library('upload', $config);
if ($this->upload->do_upload('cv')) {
return $this->upload->data("file_name");
}
return "default.pdf";
}
private function _uploadSuratMagang()
{
$config['upload_path'] = './upload/pegawaimagang/suratmagang/';
$config['allowed_types'] = 'pdf';
$config['file_name'] = $this->id;
$config['overwrite'] = true;
$config['max_size'] = 2048;
$this->load->library('upload', $config);
if ($this->upload->do_upload('sm')) {
return $this->upload->data("file_name");
}
return "default.pdf";
}
}
我希望将所有输入文件中的所有数据保存到我的数据库中,并将文件保存到不同的路径文件夹中,但是我只能将一个文件保存在一个文件夹中。