2016-04-25 51 views
0

是我第一次使用CI篝火 爲什麼我的結果,圖像不會出現this my results詞篝火上傳圖片無法上傳到destinated目錄

,這我控制器

public function tambah(){ 
    $config['upload_path'] = './gambar/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = '1000'; 
    $config['max_width'] = '2000'; 
    $config['max_height'] = '1024'; 

      $this->upload->initialize($config); 
      if(!$this->upload->do_upload('gambar')){ 
       $gambar=""; 
      }else{ 
       $gambar=$this->upload->file_name; 
      } 

      $info=array(
       'id'=>$this->input->post('id'), 
       'jenis'=>$this->input->post('jenis'), 
       'nama'=>$this->input->post('nama'), 
       'harga'=>$this->input->post('harga'), 
       'pemasok'=>$this->input->post('pemasok'), 
       'gambar'=>$gambar 
      ); 
      $this->model_barang->input_data($info); 
      redirect('barang/tampil'); 
} 

有我的模型,我認爲我沒有發現任何錯誤

<?php class Model_barang extends CI_Model{ 
private $table="barang"; 
public function tampil_data(){ 
    return $this->db->get('barang'); 
} 
public function input_data($jenis){ 
    $this->db->insert($this->table,$jenis); 
    return $this->db->insert_id(); 
} 
public function hapus($where,$table){ 
    $this->db->where($where); 
    $query = $this->db->get($table); 
    $row = $query->row(); 
    unlink('./gambar/'.$row->gambar); 
    $this->db->delete($table,$where); 
} 
public function edit_data($where,$table) { 
    return $this->db->get_where($table,$where); 
} 
public function update($where,$data,$table){ 
    $this->db->where($where); 
    $query = $this->db->get($table); 
    $row = $query->row(); 
    $this->db->where($where); 
    unlink('./gambar/'.$row->gambar); 
    $this->db->update($table,$data); 
} } 

這是我的表單輸入

<form action="<?php echo base_url(). 'index.php/barang/tambah'; ?>" method="post" enctype="multipart/form-data"> 
    <fieldset> 
     <legend><h3>Tambah Data Barang</h3></legend> <br /> 
      ID Barang <input type="text" name="id" required> <br /> <br /> 
      Jenis Barang 
      <select name="jenis" class="form-control"> 
      <option value="Teknologi">Teknologi</option> 
      <option value="Alat Petani">Alat Petani</option> 
      <option value="Kebutuhan Rumah Tangga">Kebutuhan Rumah Tangga</option> 
      <option value="Alat Tulis">Alat Tulis</option> 
      <option value="Perabotan Sekolah">Perabotan Sekolah</option> 
      </select><br /> <br /> 
      Nama Barang<input type="text" name="nama" required> <br /> <br /> 
      Harga Barang<input type="number" name="harga" required> <br /> <br /> 
      Pemasok<input type="text" name="pemasok" required> <br /> <br /> 
      <input type="file" name="gambar" value="<?php echo set_value('gambar', isset($barang['gambar']) ? $barang['gambar'] : ''); ?>"> <br /> <br /> 
      <button class="tombol">Tambah</button> 
    </fieldset> 
</form> 

,並有我的觀點的數據

<table style="margin:50px auto;" border="1" width="800" height="300" class="zebra-table"> 
    <tr> 
     <th>No</th> 
     <th>ID</th> 
     <th>Jenis</th> 
     <th>Nama</th> 
     <th>harga</th> 
     <th>pemasok</th> 
     <th>Gambar</th> 
     <th>Aksi</th> 
    </tr> 
    <?php 
    $no = 1; 
    foreach($barang as $q){ 
    ?> 
    <tr> 
     <td><?php echo $no++ ?></td> 
     <td><?php echo $q->id ?></td> 
     <td><?php echo $q->jenis ?></td> 
     <td><?php echo $q->nama ?></td> 
     <td><?php echo currency_format($q->harga) ?></td> 
     <td><?php echo $q->pemasok ?></td> 
     <td><img src="<?php echo base_url('./gambar/'.$q->gambar);?>" height="100px" width="100px"></td> 
     <td><?php echo anchor('barang/hapus/'.$q->id,'Hapus', ['onclick'=>'return confirm(\'Apakah Anda Yakin\')']); ?> | <?php echo anchor('barang/edit/'.$q->id,'Edit') ?></td>  
    </tr> 
    <?php } ?> 
</table> 

我不知道任何錯誤在此代碼

回答

0

如果你沒有安裝過程中收到錯誤嘗試

<?php echo base_url('/gambar/'.$q->gambar);?> 

<?php echo base_url('gambar/'.$q->gambar);?> 

我們不知道你的base_url();

但我不知道你的錯誤。我猜想圖像路徑中存在錯誤。您可以打開新的選項卡圖像路徑,然後您可以檢查。

+0

okey,感謝您的解答 – Qotada

+0

歡迎您。 – cgds