Postingan lainnya
Kelas Premium!
Belajar bikin website dari nol sekarang
Gunakan kupon "lebihcepat" untuk diskon 25%!
Image tidak ke upload data masuk ke database
Gini bro gw punya upload gambar nih nah data yang diupload sudah berhasil masuk ke database, nasnya imagenya itu gagal ke Upload, atau gak masuk ke folder bro ada saran gak ?
Controller
public function kadd(){
$this->form_validation->set_rules('ni', 'Nomor Invoice', 'required');
$this->form_validation->set_rules('an', 'Atas Nama', 'required');
$this->form_validation->set_rules('konfirm','Bukti Tranfer', 'required');
if ($this->form_validation->run() === TRUE) {
$usrnm = $this->input->post('usrnm');
$dates = date('d').time();
$nama = $usrnm.'konfirmasi'.$dates.'.jpg';
$this->upload->initialize(array(
'upload_path' => './uploads/konfirmasi',
'allowed_types' => 'gif|jpg|png|jpeg',
'max_size' => 1028,
'file_name' => $nama
));
if (!$this->upload->do_upload("konfirm")) {
$hahe = 'Gagal';
} else {
$hahe = 'Berhasil';
}
$data = array('usr_kfrm' => $this->input->post('usrnm'),
'invoice_kfrm' => $this->input->post('ni'),
'nama_kfrm' => $this->input->post('an'),
'tujuan_kfrm' => $this->input->post('rt'),
'bukti_kfrm' => $nama);
$data = $this->security->xss_clean($data);
$query = $this->m_konfirm->insert($data);
if ($hahe === 'Berhasil') {
$messages = false;
if ($query){
$message = array('status' => true, 'message' => 'Berhasil Input Konfirmasi');
} else {
$message = array('status' => false, 'message' => 'Gagal Input Konfirmias');
}
} else {
$messages = array('status' => false, 'message' => $this->upload->display_errors());
}
$this->session->set_flashdata('messages', $messages);
if ($messages) {
$this->session->set_flashdata('messages', $messages);
}
redirect('profile/konfirmasi', 'refresh');
}
View
<?= form_open('profile/kadd');?>
<div class="row">
<?php if(validation_errors()): ?>
<div class="col-lg-12">
<div class="alert alert-warning">
<strong>Warning!</strong>
<?php echo validation_errors('<p>', '</p>'); ?>
</div>
</div>
<?php endif; ?>
<?php if(!is_null($this->session->flashdata('messages')) AND !is_null($this->session->flashdata('message'))): ?>
<div class="col s12">
<div class="alert <?php echo ($this->session->flashdata('messages')['status']) ? 'alert-success' : 'alert-warning'; ?>">
<span class="white-text"><?php echo $this->session->flashdata('messages')['message']; ?></span>
</div>
</div>
<div class="col s12">
<div class="alert <?php echo ($this->session->flashdata('message')['status']) ? 'alert-success' : 'alert-warning'; ?>">
<span class="white-text"><?php echo $this->session->flashdata('message')['message']; ?></span>
</div>
</div>
<?php endif; ?>
<div class="form-group col-sm-12">
<label for="nama">Username :</label>
<input id="card-holder" type="text" name="username" class="form-control" value="<?= $where[0]->username ?>" disabled>
<input type="hidden" name="usrnm" value="<?= $where[0]->username ?>">
</div>
<div class="form-group col-sm-12">
<label for="nama">Nomor Invoice :</label>
<input id="card-holder" type="text" name="ni" class="form-control" placeholder="Masukan Nomor Invoice Anda">
</div>
<div class="form-group col-sm-12">
<label for="alamat">Atas Nama :</label>
<input type="text" name="an" class="form-control" placeholder="Pembayaran Atas Nama">
</div>
<div class="form-group col-sm-12">
<label for="alamat">Rekening Tujuan :</label>
<input type="text" name="rt" class="form-control" placeholder="EX: BRI, MANDIRI, PERMATA">
</div>
<div class="form-group col-sm-12">
<?php
$att = array('class' => 'label-material',);
echo form_label('Upload Bukti Tranfer','konfirm', $att);
$data= array(
'name' => 'konfirm',
'type' => 'file',
'class' => 'form-control',
'accept' => 'image/*',
);
echo form_input($data);
?>
</div>
<div class="form-group col-sm-12" style="margin-top: 10px;">
<button type="submit" name="Konfirmasi" class="btn btn-primary btn-block">Kirim Konfirmasi</button>
</div>
</div>
<?= form_close();?>
jadi errornya itu pada saat uppload gambar dan tidak Work, ada saran atau ada yg salah dengan code ane ?
1 Jawaban:
Jawaban Terpilih
cek "file permissionnya" set ke 777 atau dibolehkan menulis ke dalam folder itu, cek juga <a href=' https://www.codeigniter.com/userguide3/libraries/file_uploading.html '>dokumentasii upload gambar codeigniter</a> ini
Tanggapan
tapi kan itu di localhost bang, sebelumnya ane pernah buat juga upload file tapi multiple
maksudnya? 1. "itu" tuh apa 2. Upload file multplenya kenapa? berhasil? kalau sudah berhasil harusnya sama dengan yang tidak multiple
iy bang saya baru ngeh... kalau array harusnya menggunakan multipart, kalau 1 gak pakai multipart ini mash saya coba