[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">
<?php
foreach($hasil->result() as $row) :
$isi = $row->isi;
$isi = substr($isi, 0, 200);
?>
<h2><span><?php echo anchor('cartikel/view/'.$row->id_artikel, $row->judul); ?></span></h2>
<div class="clr"></div>
<small><underline>Ditulis oleh: <?php echo $row->penulis;?> Tanggal : <?php echo $row->tanggal;?></underline></small></p>
<img src="<?php echo base_url()?>folder/images/thumbs/<?php echo $row->gambar;?>" width="613" height="179" alt="image" />
<p> <?php echo $isi;?><div class="clr"></div><div class="clr"></div> <a href="<?php echo site_url('cartikel/view/'.$row->id_artikel,$row->judul);?>">Read More</a></p>
<?php
endforeach;
echo $this->pagination->create_links();
?>
</div>
view input image
Code:
<html>
<head>
<title> Tambah Artikel</title>
<?php echo $xinha_java;?>
</head>
<body>
<h3> Tambah Data </h3>
<?php echo form_open_multipart('content/tambah_artikel'); ?>
<table>
<tr>
<td class="td"> Judul </td>
<td class="td"> : </td>
<td> <?php echo form_input('judul');?> </td>
</tr>
<?php echo date('Y-m-d');?>
<tr valign="top">
<td class="td"> Isi </td>
<td class="td"> : </td>
<td>
<?php
$textarea = array (
'name' => 'isi',
'id' => 'isi',
'cols' => '65',
'rows'=>'20',
);
echo form_textarea($textarea);
?>
</td>
</tr>
<tr>
<td class="td"> Gambar </td>
<td class="td"> : </td>
<td><?php echo form_upload('userfile'); ?> </td>
</tr>
<tr>
<td> <?php echo form_submit('submit', 'Simpan', 'id="submit"'); ?></td>
</tr>
</table>
<?php echo form_close();?>
</body>
</html>
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 ;