file image tidak terinput di database

saya menggunakan phpmyadmin, saat di local file image dapat terupload. tapi ketika saya upload projectnya di winscp, dan saya coba upload data.. data text masuk ke phpmyaadmin tapi yang data image tidak masuk. saya sudah membuat folder metadata di folder upload.

berikut syntax controllers-nya

function edit($id=0) {
		if ($id < 1) {
			$datanya = array(
				"id"=>$id,
				"indikator"=>"",
				"definisi"=>"",
				"rumus"=>"",
				"interpretasi"=>"",
				"penanggung_jawab"=>"",
				"keterangan"=>"",
				"required"=>"required"
			);
		} else {
			$this->db->where("id", $id);
			$datanya = $this->db->get("metadata")->row_array();
			$datanya['required'] = "";
		}

		$d['url'] = $this->url;
		$d['data'] = $datanya;
		$d['p'] = "form";
		$d['title'] = "Metadata";
		$d['menu_aktif'] = 5;
		$d['bredkum'] = bredkum(array("metadata"=>$d['title']), "metadata");

		$this->load->view('template', $d);
	}
	function detail($id=0) {
		if ($id < 1) {
			$datanya = array(
				"id"=>$id,
				"indikator"=>"",
				"definisi"=>"",
				"rumus"=>"",
				"interpretasi"=>"",
				"penanggung_jawab"=>"",
				"keterangan"=>"",

				"required"=>"required"
			);
		} else {
			$this->db->where("id", $id);
			$datanya = $this->db->get("metadata")->row_array();
			$datanya['required'] = "";
		}

		$d['url'] = $this->url;
		$d['data'] = $datanya;
		$d['p'] = "detail";
		$d['title'] = "Metadata";
		$d['menu_aktif'] = 5;
		$d['bredkum'] = bredkum(array("metadata"=>$d['title']), "metadata");
		// echo "<pre>";
		// print_r($d);
		// echo "</pre>";
		// exit;

		$this->load->view('template', $d);
	}

	function save() {

		$p = $this->input->post();
		$id = intval($p['id']);
		$indikator = $p['indikator'];
		$interpretasi = $p['interpretasi'];
		$definisi = $p['definisi'];
		$penanggung_jawab = $p['penanggung_jawab'];
		$keterangan = $p['keterangan'];

		$pdata = array(
			"indikator"=>$indikator,
			"definisi"=>$definisi,
			"interpretasi" => $interpretasi,
			"penanggung_jawab" => $penanggung_jawab,
			"keterangan" => $keterangan,
		);

		if ($id > 0) {

			$rumus='';
			if (isset($_FILES['rumus']['name'])) {
				$config['upload_path'] = './upload/metadata/';
				$config['allowed_types'] = 'jpg|jpeg|png|gif';
				$config['max_size'] = '2048';
				$config['overwrite'] = FALSE;
				$config['remove_space'] = TRUE;
				$config['encrypt_name'] = TRUE;

				$this->load->library('upload');
				$this->upload->initialize($config);

				if($this->upload->do_upload('rumus')){
					$get_file = $this->db->where("id",$id)->get("metadata")->row_array();
					@unlink("./upload/metadata/".$get_file['rumus']);
					$rumus = $this->upload->data('file_name');

				}
			}
			$pdata['rumus'] = $rumus;

			if ($_FILES['rumus']['name'] == '') {
				unset($pdata['rumus']);
			}

			$this->db->set($pdata);
			$this->db->where('id', $id);
			$this->db->update('metadata', $pdata);
		}else{
			$rumus = '';
			if (isset($_FILES['rumus']['name'])) {
				$config['upload_path'] = './upload/metadata/';
				$config['allowed_types'] = 'jpg|jpeg|png|gif';
				$config['max_size'] = '2048';
				$config['overwrite'] = FALSE;
				$config['remove_space'] = TRUE;
				$config['encrypt_name'] = TRUE;

				$this->load->library('upload');
				$this->upload->initialize($config);

				if($this->upload->do_upload('rumus')){
					$rumus = $this->upload->data('file_name');

				}
			}

			$pdata['rumus'] = $rumus;
			$this->db->insert('metadata',$pdata);
		}

		$this->session->set_flashdata('k', '<div class="alert alert-danger">Berhasil mengubah data</div>');
		redirect($this->url);
avatar aziima27
@aziima27

20 Kontribusi 11 Poin

Diperbarui 3 tahun yang lalu

1 Jawaban:

<div>sepertinya programnya perlu di refactor sedikit<br>dalam pengembangan aplikasi biasakan untuk melakukan throw error atau menampilkan errornya sehingga kita dapat menyelesaikan permasalahannya<br><br>untuk refactor yang bisa dilakukan mungkin kamu bisa melakukan else pada proses upload foto<br>karena di sana hanya if ketika file di upload maka tambahkanlah else dengan isi sbb :<br><br></div><pre>$error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());

var_dump($error); die;</pre>

avatar insanz01
@insanz01

90 Kontribusi 56 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban