Codeigniter Resim Upload
Bu yazıda codeigniter ile resim upload ve thumbs resim oluşturma kodunu paylaşacağım. Malumunuz codeigniter framework kullananların ilk tercihlerinden biri. (Bende Bunlardan birisiyim. :D) Türkçe kaynaklarıda yavaş yavaş artmaya başladı. Bizde bu konuda bir şeyler yapmaya çalışıyoruz olabildiğince. ;) Şimdi gelelim resim upload olayına.

Controller Dosyasının İçeriği :

if ($this->input->post('upload')) {
$this->load->model('resim_mdl');
$this->resim_mdl->do_upload();
}
$this->load->view('gallery', $data);


Model Dosyasının İçeriği :

class Resim_mdl extends CI_Model {
var $dosya_yolu;
function __construct() {
parent::__construct();
$this->dosya_yolu= realpath(APPPATH . '../images');
}
function do_upload() {
$filename = 'resim_' . time() . '_' . rand(0, 9);
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->dosya_yolu,
'file_name' => $filename,
'max_size' => 2000
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
$config = array(
'image_library' => 'gd2',
'source_image' => $image_data['full_path'],
'new_image' => $this->dosya_yolu.'/thumbs',
'file_name' => $filename,
'maintain_ration' => true,
'width' => 150,
'height' => 100
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
}

View Dosyası İçeriği :

< ?php
echo form_open_multipart('gallery');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
? >

Okunma Sayısı : 250

Yorumlar


Hiç Yorum Yapılmamış. İlk Yorumu Siz Yapın.

Twitter Günlüğü