Welcome Guest, Not a member yet? Register   Sign In
Help about image upload and thumb resizing.
#1

[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>
&lt;?php echo validation_errors('<p class="error">');?&gt;
&lt;?php echo form_open_multipart('galleries_images/validate'); ?&gt;
<p>
    <label for="title">title</label>
    &lt;?php echo form_input('title',set_value('title','')); ?&gt;
</p>
<p>
    <label for="description">description</label>
    &lt;?php echo form_textarea('description',set_value('description','')); ?&gt;
</p>
<p>
    <label for="filename">filename</label>
    &lt;?php echo form_upload('userfile'); ?&gt;
</p>
<p>
    <label for="galleries_id">gallery id</label>
        <select name="galleries_id">
            &lt;?php foreach($record as $r): ?&gt;
            <option value="&lt;?php echo $r->id ?&gt;">&lt;?php echo $r->title ?&gt;</option>
            &lt;?php endforeach; ?&gt;
    </select>
</p>
<p>
   &lt;input type="submit" name="submit"/&gt;
</p>
&lt;?php echo form_close(); ?&gt;
Here is the model:
Code:
&lt;?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);
    }
#2

[eluser]danmontgomery[/eluser]
What doesn't work? What error message(s) are you getting? What have you tried?
#3

[eluser]basterz[/eluser]
That is the problem I do not have any notification or errorr the thumb is not created.
#4

[eluser]danmontgomery[/eluser]
Have you tried:
Code:
if ( !$this->image_lib->resize() ) {
    echo $this->image_lib->display_errors();
}
?
#5

[eluser]basterz[/eluser]
Yes I've just tried but still no error
#6

[eluser]mi6crazyheart[/eluser]
Have u given proper file access permission to the folder where u r storing u'r images... ?
#7

[eluser]basterz[/eluser]
Yes I've make it writeble. I do the same for the non-thumbnail images and it works fine. And I cant still solve this problem
#8

[eluser]basterz[/eluser]
Still no solution. Does anybody have some Idea why I can't create thumbnails. If someone needs more information I will post it Smile. Thanks
#9

[eluser]cryogenix[/eluser]
line 88 of your posted code "maintain_ration" is wrong. it should be "maintain_ratio"...

just my hunch.... not sure...




Theme © iAndrew 2016 - Forum software by © MyBB