Upload type file berbeda di CI

gan mau tanya caranya upload file yg berbeda type gimana ya.. saya mau upload file png dan pdf dalam 1 form gambarnya udah ke upload tapi filename blm bisa ke simpan didatabase.. mohon bantuannya gan.

ini script Controllernya gan

 public function tambah_action()
	{
		$this->_rules();

		if ($this->form_validation->run() == FALSE) {
			$this->tambah();
		} else {
			$input = array(
				'ID_SarPen' => $this->input->post('ID_SarPen',TRUE),
				'Merk_AC' => $this->input->post('Merk_AC',TRUE),
				'Kondisi_AC' => $this->input->post('Kondisi_AC',TRUE),
				'Daya_AC' => $this->input->post('Daya_AC',TRUE),
				'Kondisi_ExF' => $this->input->post('Kondisi_ExF',TRUE),
				'Foto_SarPen' => "",
				'File_SarPen' => "",
				);
			$data['input']=$input;
			$this->load->library('upload');
			$config['upload_path'] = 'public/upload/';
			$config['allowed_types'] = 'jpg|png';
			$config['overwrite'] = FALSE;
			$this->upload->initialize($config);
			if (!$this->upload->do_upload('Foto_SarPen')) {
				$this->session->set_flashdata('message', 'Type Data tidak diizinkan');
				redirect(site_url('home/tambah'));
			} else {
				unset($config);
				$config['upload_path'] = 'public';
				$config['allowed_types'] = 'pdf';
				$config['overwrite'] = FALSE;
				$this->upload->initialize($config);
				if (!$this->upload->do_upload('File_SarPen')) {
					$this->session->set_flashdata('message', 'Type Data tidak diizinkan harus PDF');
					redirect(site_url('home/tambah'));
				} else {
					$this->Sarpen_pop_model->insert($input);
					$this->session->set_flashdata('message', 'Data berhasil di Tambah');
					redirect(site_url('home'));

				}
			}
		}
	}
avatar niko069
@niko069

48 Kontribusi 11 Poin

Diperbarui 7 tahun yang lalu

1 Jawaban:

Mungkin karena di dalam array $input, fotoSarpen atau fileSarpennya blm dikasih nama.. mungkin bisa ditambahin jadi

'FotoSarpen' => $_FILES['FotoSarpen']['name'], 'FileSarpen' => $_FILES['FileSarpen']['name']

avatar demaram
@demaram

51 Kontribusi 33 Poin

Dipost 7 tahun yang lalu

Login untuk ikut Jawaban