gambar gagal upload atau tidak tersimpan pada direktori

Controller
 public function simpan()
        {
            
            $config['upload_path']  = './gambar/';
            $config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
            $config['max_size'] = 0;
            $config['max_width'] = 1024;
            $config['max_height'] = 768;

            $this->upload->initialize($config);

            if ( ! $this->upload->do_upload('berkas')) {
                echo "
                        <script type='text/javascript'>
                            //<![CDATA[
                                alert('WARNING: Coba Lagi!!');
                                window.location='./'
                                //]]>
                        </script>";
            }else{

                $img =  $this->upload->data();
                $pathToUploadedFile = $img['full_path'];
                $filenama = $img['file_name'];
                $lokasi =  $config['upload_path'] . $filenama;
                $post['image'] = $lokasi;
                $post['judul'] = htmlentities(strip_tags($this->input->post('judul')));
                $post['id_categori']  = htmlentities(strip_tags($this->input->post('id')));
                date_default_timezone_set('Asia/Jakarta');
                $post['tgl_input'] = date('Y-m-d H:i:s');
                $post['post'] = $this->input->post('isi');

                $kirim = $this->Model->save_artikel($post);

                if ($kirim) {
                    echo "
                        <script type='text/javascript'>
                            //<![CDATA[
                                alert('SUCCESS: Berhasil simpan!!');
                                window.location='./'
                                //]]>
                        </script>";
                } 
            }

        } 
Form
  <form role="form" action="index.php/admin/simpan" enctype="multipart/form-data" method="post">
                  <div class="box-body">
                    <div class="form-group">
                      <label for="exampleInputEmail1">Judul</label>
                      <input type="text" name="judul" class="form-control" id="exampleInputEmail1" required>
                    </div>

                    <!-- select -->
                    <div class="form-group">
                      <label>Categori</label>
                      <select name="id" class="form-control">
                        <?php foreach ($ct->result() as $baris) { ?>
                          <option value="<?php echo $baris->id_categori; ?>"> <?php echo $baris->categori; ?></option>
                        <?php ;
                        } ?>
                      </select>
                    </div>

                    <div class="form-group">
                      <label for="exampleInputFile">File input</label>
                      <input type="file" name="berkas" accept="image/*" onchange="tampilkan(this,'preview')" id="exampleInputFile"> <br>
                      <img src='img/kosong.jpg' id='preview' alt='...' style='width:202px; height:205px;border:1px solid green;padding:10px;' class='img-responsive'>
                    </div>

                    <script>
                      function tampilkan(val) {
                        $("#preview").attr('src', URL.createObjectURL(event.target.files[0]));
                      }
                    </script>

                    <div class="form-group">
                      <label for="exampleInputFile">Artikel</label>
                      <textarea name="isi" id="" class="ckeditor"></textarea>
                    </div>
                  </div>
                  <!-- /.box-body -->
                  <div class="box-footer">
                    <button type="submit" class="btn btn-primary">Post</button>
                  </div>
                </form>
avatar promoteus

@promoteus

2 Kontribusi 0 Poin


Jawaban

Pastikan direktori tujuan untuk menyimpan file yang diupload nya sudah ada, kemudian jika kamu menggunakan linux, pastikan access permission direktorinya sudah di set ke 777
avatar ahanafi

@ahanafi

745 Kontribusi 486 Poin


Login untuk gabung berdiskusi
premium logo tube

Hey, sedang ada diskon premium untuk akses semua kelas. Lihat di sini