Welcome Guest, Not a member yet? Register   Sign In
thumbnail question
#1

[eluser]shiva478[/eluser]
I'm trying to get thumbnails out of the images I uploaded but it doesn't upload in the thumbs folder and it doesn't show up on the web page.

This is my controller
Code:
class Admin extends CI_Controller
{
public function __construct()
{
  parent::__construct();
  $this->load->helper('form');
  $this->load->helper('url');
}

        function createThumbnail() {
              $config['image_library'] = 'gd2';
              $config['source_image'] = './uploads/';
              $config['new_image'] = './uploads/thumbs/';
              $config['create_thumb'] = TRUE;
              $config['maintain_ratio'] = TRUE;
              $config['width'] = 75;
              $config['height'] = 75;

              $this->load->library('image_lib', $config);
              if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
        }

        function bra_view($bra_id)
{
  $data['bra_item'] = $this->admin_model->get_bras($bra_id);

         if (empty($data['bra_item']))
        {
   show_404();
        }

          $data['title'] = $data['bra_item']['title'];

         $this->createThumbnail($data['bra_item']['filename']);

                $this->image_lib->clear();

         $this->load->view('admin/bras/bra_view', $data);

           }



function bra_create(){
  
  $this->load->model('admin_model');
  $this->load->helper('form');
          $this->load->library('form_validation');

         $data['title'] = 'Create a bra item';

  $config['upload_path'] = './uploads/';

  $config['allowed_types'] = 'gif|jpg|png';
  $config['max_size'] = '100';
  $config['max_width']  = '1024';
  $config['max_height']  = '768';

  $this->load->library('upload', $config);

  if ( ! $this->upload->do_upload())
  {
   $error = array('error' => $this->upload->display_errors());

   $this->load->view('admin/bras/bra_create', $error);
  }
  else
  {
   $data = array('upload_data' => $this->upload->data());
   $upload_info = $this->upload->data();
   $slug = url_title($this->input->post('title'), 'dash', TRUE);
  
$insert_data = array(                          
                 'bra_id' => $this->input->post('bra_id'),                        
                 'title' => $this->input->post('title'),              
                 'slug' => $slug,              
                 'image_path' => $upload_info['file_path'],              
                 'filename' => $upload_info['file_name'],        
                 'content' => $this->input->post('content'),          
                 'price' => $this->input->post('price')
              
              );
   $this->db->insert('bras', $insert_data);
                 $this->load->view('admin/success', $data);
  }
}
#2

[eluser]vitoco[/eluser]
From :

Image manipulation class - USER GUIDE

You must specify the origin picture ( not only the path ) , so this :

Code:
function createThumbnail() {
              $config['image_library'] = 'gd2';
              $config['source_image'] = './uploads/';
              $config['new_image'] = './uploads/thumbs/';
              $config['create_thumb'] = TRUE;
              $config['maintain_ratio'] = TRUE;
              $config['width'] = 75;
              $config['height'] = 75;

              $this->load->library('image_lib', $config);
              if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
        }

.......
         // HERE YOU PASS THE FILENAME AS PARAM , THAT'S OK
         // BUT IN THE FUNCTION createThumbnail() YOU DIDN'T RECEIVE IT
         $data['title'] = $data['bra_item']['title'];
         $this->createThumbnail($data['bra_item']['filename']);
.......

Must change to this :

Code:
function createThumbnail( $filename ) { // <-- RECEIVE THE FILENAME
              $config['image_library'] = 'gd2';
              $config['source_image'] = './uploads/'.$filename ; // <-- APPEND THE FILENAME
              $config['new_image'] = './uploads/thumbs/';
              $config['create_thumb'] = TRUE;
              $config['maintain_ratio'] = TRUE;
              $config['width'] = 75;
              $config['height'] = 75;

              $this->load->library('image_lib', $config);
              if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
        }

Saludos
#3

[eluser]shiva478[/eluser]
I added the $filename but it still didn't work
#4

[eluser]vitoco[/eluser]
From where are you calling bra_view($bra_id) to resize de uploaded image? i don't see the calling anywhere
#5

[eluser]shiva478[/eluser]
The bra_view($bra_id) is in my model

Code:
&lt;?php

class Admin_model extends CI_Model
{

public function get_bras($bra_id = FALSE)
{
if ($bra_id === FALSE)
{
  $query = $this->db->get('bras');
  return $query->result_array();
}

$query = $this->db->get_where('bras', array('bra_id' => $bra_id));
return $query->row_array();
}




Theme © iAndrew 2016 - Forum software by © MyBB