[eluser]basterz[/eluser]
Hello guys I am a newbie in codeigniter and programing. I am trying to make a method that uploads and makes a thumb. I looked at net.tutsplus.com tutorial about this image manipulations but there is something that wont work for me. So I will be very grateful if somebody helps me. So about the problem. I do manage to move the file to the expected dir that i want. I gave permitions to the both folders but still there is no thumb image.
OK here is my controller
Code:
<?php
class Galleries_images extends Controller {
function __construct() {
parent::Controller();
$this->is_logged_in();
$this->gallery_path = realpath(APPPATH . '../upload/galleries_images/');
$this->gallery_path_url = base_url().'upload/galleries_images/';
}
function create() {
$this->load->model('galleries_model');
//print_r($gallery);
$view['main_content'] = 'galleries_images/galleries_images_add_view';
$view['record'] = $this->galleries_model->getAllGalleries();
$this->load->view('layout',$view);
}
function validate() {
$this->form_validation->set_rules('title','Title','trim|required');
$this->form_validation->set_rules('description','Description','trim');
if($this->form_validation->run()==False) {
$this->create();
}
else {
$file_name = $this->upload();
$data = array
(
'title' => $this->input->post('title'),
'description' =>$this->input->post('description'),
'filename' =>$file_name,
'galleries_id' =>$this->input->post('galleries_id'),
);
$this->load->model('galleries_images_model');
$data = $this->galleries_images_model->addRecord($data);
$this->index();
}
}
function delete() {
$this->load->model('galleries_images_model');
$this->galleries_images_model->deleteRecord();
$this->index();
}
function edit() {
$data= array();
$id = $this->uri->segment(3);
$this->load->model('galleries_images_model');
$query= $this->galleries_images_model->showRecord($id);
$data['records'] = $query;
$data['main_content'] = 'galleries_images/galleries_images_edit_view';
$this->load->view('layout',$data);
}
function update() {
$data = array
(
'title' => $this->input->post('title'),
'description' =>$this->input->post('description'),
'filename' => $this->input->post('filename'),
'galleries_id' =>$this->input->post('galleries_id'),
);
$id = $this->uri->segment(3);
$this->load->model('galleries_images_model');
$data['records'] = $this->galleries_images_model->updateRecord($id, $data);
$this->index();
}
function is_logged_in() {
// print_r($_SESSION);
$is_logged_in = $this->session->userdata('is_logged_in');
if(!isset($is_logged_in)|| $is_logged_in != true) {
echo anchor('login/index','login');
die();
}
}
function upload() {
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->gallery_path,
'max_size' => 2000
);
$this->load->library('upload',$config);
if(!$this->upload->do_upload()) {
echo $this->upload->display_errors();
}
else {
$image_data = $this->upload->data();
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path,
'maintain_ration' => true,
'width' => 300,
'height' => 300
);
echo $image_data['full_path'];
$this->load->library('image_lib', $config);
$this->image_lib->resize();
return $image_data ['file_name'];
}
}
}
?>
This is my view:
Code:
<h2>Add Gallery Image Record</h2>
<?php echo validation_errors('<p class="error">');?>
<?php echo form_open_multipart('galleries_images/validate'); ?>
<p>
<label for="title">title</label>
<?php echo form_input('title',set_value('title','')); ?>
</p>
<p>
<label for="description">description</label>
<?php echo form_textarea('description',set_value('description','')); ?>
</p>
<p>
<label for="filename">filename</label>
<?php echo form_upload('userfile'); ?>
</p>
<p>
<label for="galleries_id">gallery id</label>
<select name="galleries_id">
<?php foreach($record as $r): ?>
<option value="<?php echo $r->id ?>"><?php echo $r->title ?></option>
<?php endforeach; ?>
</select>
</p>
<p>
<input type="submit" name="submit"/>
</p>
<?php echo form_close(); ?>
Here is the model:
Code:
<?php
class Galleries_images_model extends Model
{
function getAllRecords()
{
$query = $this->db->get('galleries_images');
return $query->result();
}
function addRecord($data)
{
$this->db->insert('galleries_images', $data);
return;
}
function showRecord($id)
{
$query = $this->db->getwhere('galleries_images',array('id'=>$id));
return $query->row_array();
}
function updateRecord($id, $data)
{
$this->db->where('id',$id);
$this->db->update('galleries_images',$data);
}