09-03-2012, 11:36 AM
[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
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);
}
}