[eluser]meer[/eluser]
i have to create a library of the folllowing image style files
what will be the best ????
my codes are as folllows
controller........
<?php
if(!defined('BASEPATH'))exit("NO DIRECT SCRIPTS ALLOWED ");
class Admin_controller extends CI_Controller{
function index()
{
$this->load->model('admin_model');
$data['result'] = $this->admin_model->set_admin();
$this->load->view('admin_view',$data);
}
function add_images()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->form_validation->set_rules('hover','hover','required');
$this->form_validation->set_rules('description','Description','required');
$this->form_validation->set_rules('image', 'Image', 'callback__do_upload');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('myform1');
}
else
{
$temp=$this->upload->data();
$filename=$temp['file_name'];
$fullpath=$temp['full_path'];
$hover = $this->input->post('hover');
$description = $this->input->post('description');
$this->load->model('admin_model');
$this->admin_model->add_image($filename,$fullpath,$hover,$description);
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success',$data);
}
}
function delete_images($id)
{
$query=$this->db->get_where('add_images', array('id'=>$id));
foreach($query->result() as $row)
{
$file_name = $row->image;
unlink("images/".$file_name);
unlink("images/thumbs/".$file_name);
}
$this->db->delete('add_images',array('id'=>$id));
redirect('admin_controller/', 'location' );
}
public function _do_upload()
{
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$field_name = 'image';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload($field_name))
{
$this->form_validation->set_message('_do_upload', $this->upload->display_errors());
return FALSE;
}
else
{
$image_data = $this->upload->data();
$filename = $image_data['file_name'];
$config = array
(
'source_image' => $image_data['full_path'],
'new_image' => './images/thumbs/',
'maintain_ratio' => false,
'width' => 300,
'height' => 200
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
return TRUE;
}
}
}
model........
<?php
class Admin_model extends CI_Model{
function set_admin()
{
$this->db->select('id,hover,desc,image,fullpath');
$this->db->from('add_images');
$query = $this->db->get();
if($query->num_rows()>0)
{
return $query->result();
}
else
{
return false;
}
}
function add_image($filename,$fullpath,$hover,$description)
{
$data=array('image'=>$filename,
'fullpath'=>$fullpath,
'hover'=>$hover,
'desc'=>$description
);
$this->db->insert('add_images', $data);
}
}
view......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p> </p>
<p> </p>
<form id="form1" name="form1" method="post" action="">
<p> </p>
<p> </p>
<table width="536" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="536" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3" align="center"><h2>ADMINISTRATION AREA</h2></td>
</tr>
<tr>
<td colspan="2" align="center"><a href="admin_controller/add_images/"><strong>ADD MORE IMAGES</strong></a></td>
</tr>
<?php foreach($result as $row ) { ?>
<tr>
<td width="273" height="82" align="center"><img src="<?php echo base_url(); ?>images/<?php echo $row->image; ?>" height="80" width="120" /></td>
<td width="261" align="center"><a href="admin_controller/delete_images/<?php echo $row->id; ?>"><strong>DELETE</strong></a></td >
</tr>
<?php } ?>
<tr>
<td colspan="2" align="center">~~~~~~~~~~~~~~~~~</td>
</tr>
<tr>
<td colspan="2" align="center"><a href="admin_controller/add_images/"><strong>ADD MORE IMAGES</strong></a></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
</form>
</body>
</html>
i hope u will understand.....