Welcome Guest, Not a member yet? Register   Sign In
Upload Images on CI 2.0
#1

[eluser]Unknown[/eluser]
I have problems at the time i make upload images on CI 2.0
Model
Code:
<?php
Class M_artikel extends CI_model {
             var $gallerypath;
                    var $gallery_path_url;
                   function __construct() {
                parent::__construct();
                    $this->gallerypath = realpath(APPPATH . '../images');
                    $this->gallery_path_url = base_url().'folder/images/';
            }
                function do_upload() {
                    $konfigurasi = array(
   'allowed_types' =>'jpg|jpeg|gif|png|bmp',
   'upload_path' => $this->gallerypath
                    );
                    $this->load->library('upload', $konfigurasi);
                    $this->upload->do_upload();
                    $datafile = $this->upload->data();

                    $konfigurasi = array(
   'source_image' => $datafile['full_path'],
   'new_image' => $this->gallerypath . '/thumbs',
   'maintain_ration' => true,
   'width' => 160,
   'height' =>120
                    );

  $this->load->library('image_lib', $konfigurasi);
  $this->image_lib->resize();
  $judul = $this->input->post('judul');
  $isi = $this->input->post('isi');
                $tanggal = date('Y-m-d');
  $userfile = $_FILES['userfile']['name'];
  $data = array(
   'judul' => $judul,
   'isi' => $isi,
                        'tanggal' => $tanggal,
   'gambar' => $userfile
   );
  $this->db->insert('artikel', $data);
                }
        }
?>
Controller
Code:
<?php
Class Content extends CI_Controller {
    function __construct() {
        parent::__construct();
         $this->load->model('M_artikel');
         $this->load->model('Users_model');
    }
     function tambah_artikel() {
          $sessionData = $this->session->userdata('id_user','full_name');           if(empty($sessionData)) {
                    redirect('users/login');
                }
                else {
                  if   ($this->input->post('submit')) {
                    $this->M_artikel->do_upload();
                    redirect('content/manajemen_artikel');
                  }
                }
               $this->load->helper('xinha_pi');
               //untuk xinha
               $data['xinha_java'] = javascript_xinha(array('isi'));
               $data['jenis'] = 'tambah_artikel';
               $this->load->view('admin/dashboard/tambah_artikel', $data);      
        }
    
        
}
?>
view show
Code:
<div class="article">
&lt;?php
foreach($hasil->result() as $row) :
    $isi = $row->isi;
    $isi = substr($isi, 0, 200);
?&gt;
    <h2><span>&lt;?php echo anchor('cartikel/view/'.$row->id_artikel, $row->judul); ?&gt;</span></h2>
          <div class="clr"></div>
          <small><underline>Ditulis oleh: &lt;?php echo $row->penulis;?&gt; Tanggal : &lt;?php echo $row->tanggal;?&gt;</underline></small></p>
          <img src="&lt;?php echo base_url()?&gt;folder/images/thumbs/&lt;?php echo $row-&gt;gambar;?&gt;" width="613" height="179" alt="image" />
          
          <p> &lt;?php echo $isi;?&gt;<div class="clr"></div><div class="clr"></div> <a href="&lt;?php echo site_url('cartikel/view/'.$row-&gt;id_artikel,$row-&gt;judul);?&gt;">Read More</a></p>  
&lt;?php    
endforeach;
echo $this->pagination->create_links();
?&gt;
</div>

view input image
Code:
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt; Tambah Artikel&lt;/title&gt;
    &lt;?php echo $xinha_java;?&gt;
     &lt;/head&gt;
     &lt;body&gt;
         <h3> Tambah Data </h3>
         &lt;?php echo form_open_multipart('content/tambah_artikel'); ?&gt;
         <table>
             <tr>
                 <td class="td"> Judul </td>
                 <td class="td"> : </td>
                 <td> &lt;?php echo form_input('judul');?&gt; </td>
             </tr>
             &lt;?php echo date('Y-m-d');?&gt;
             <tr valign="top">
                 <td class="td"> Isi </td>
                 <td class="td"> : </td>
                 <td>
                     &lt;?php
                     $textarea = array (
                         'name' => 'isi',
                         'id' => 'isi',
                         'cols' => '65',
                         'rows'=>'20',
                     );
                     echo form_textarea($textarea);
                     ?&gt;
                 </td>
             </tr>
             <tr>
<td class="td"> Gambar </td>
<td class="td"> : </td>
<td>&lt;?php echo form_upload('userfile'); ?&gt; </td>
</tr>
             <tr>
                 <td> &lt;?php echo form_submit('submit', 'Simpan', 'id="submit"'); ?&gt;</td>
             </tr>
         </table>
         &lt;?php echo form_close();?&gt;
     &lt;/body&gt;
&lt;/html&gt;

database
Code:
CREATE TABLE IF NOT EXISTS `artikel` (
  `id_artikel` int(11) NOT NULL AUTO_INCREMENT,
  `id_komentar` int(11) NOT NULL,
  `id_user` int(11) NOT NULL,
  `judul` varchar(100) NOT NULL,
  `penulis` varchar(100) NOT NULL,
  `isi` text NOT NULL,
  `tanggal` date NOT NULL,
  `gambar` text NOT NULL,
  PRIMARY KEY (`id_artikel`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=41 ;





Theme © iAndrew 2016 - Forum software by © MyBB