Last active
January 28, 2019 06:49
-
-
Save bablukpik/f7ee708da6790457edeebf9e18974ced to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function pr($data) | |
{ | |
echo "<pre>"; | |
print_r($data); | |
echo "</pre>"; | |
exit; | |
} | |
//GD2 for thumb and full size image | |
//v.01 | |
$this->load->library('image_lib'); | |
// full image stuff | |
$this->image_lib->initialize($config); | |
$this->image_lib->resize(); | |
// thumbnail stuff | |
$this->image_lib->initialize($config); | |
$this->image_lib->resize(); | |
//Thumbnails example | |
function create_thumbs() | |
{ | |
$this->load->library('image_lib'); | |
$path = "path/to/image/"; | |
$source_image = "original.jpg"; | |
$medium_image = "medium.jpg"; | |
$small_image = "small.jpg"; | |
// Resize to medium | |
$config['source_image'] = $path.$source_image; | |
$config['new_image'] = $path.$medium_image; | |
$config['width'] = 200; | |
$config['height'] = 200; | |
$this->image_lib->initialize($config); | |
if ( ! $this->image_lib->resize()) | |
{ | |
// an error occured | |
} | |
// Keep the same source image | |
$config['new_image'] = $path.$small_image; | |
$config['width'] = 50; | |
$config['height'] = 50; | |
$this->image_lib->initialize($config); | |
if ( ! $this->image_lib->resize()) | |
{ | |
// an error occured | |
} | |
} | |
//Full/Medium/small sizes thumbnail example | |
<?php | |
class Gallery_model extends CI_Model { | |
var $gallery_path; | |
function __construct() { | |
parent::__construct(); | |
$this->load->helper('functions'); | |
$this->gallery_path = realpath(APPPATH . '../uploads'); | |
} | |
function do_upload() { | |
$config = array( | |
'allowed_types' => 'jpg|jpeg|gif|png', | |
'upload_path' => $this->gallery_path, | |
'max_size' => 2000 | |
); | |
$this->load->library('upload', $config); | |
$this->upload->do_upload(); | |
$image_data = $this->upload->data(); | |
$image_sizes = array( | |
'thumb' => array(150, 100), | |
'medium' => array(300, 300), | |
'large' => array(800, 600) | |
); | |
$this->load->library('image_lib'); | |
foreach ($image_sizes as $resize) { | |
$config = array( | |
'source_image' => $image_data['full_path'], | |
'new_image' => $this->gallery_path . '-' . $resize[0] . 'x' . $resize[1], | |
'maintain_ration' => true, | |
'width' => $resize[0], | |
'height' => $resize[1] | |
); | |
$this->image_lib->initialize($config); | |
$this->image_lib->resize(); | |
$this->image_lib->clear(); | |
} | |
} | |
} | |
//v.02 | |
<?php | |
if (!defined('BASEPATH')) | |
exit('No direct script access allowed'); | |
class Manipulation_Controller extends CI_Controller { | |
// Load Library. | |
function __construct() { | |
parent::__construct(); | |
$this->load->library('image_lib'); | |
} | |
// View "manipulation_view" Page. | |
public function index() { | |
$this->load->view('manipulation_view'); | |
} | |
// Perform manipuation on image ("crop","resize","rotate","watermark".) | |
public function value() { | |
if ($this->input->post("submit")) { | |
// Use "upload" library to select image, and image will store in root directory "uploads" folder. | |
$config = array( | |
'upload_path' => "uploads/", | |
'upload_url' => base_url() . "uploads/", | |
'allowed_types' => "gif|jpg|png|jpeg|pdf" | |
); | |
$this->load->library('upload', $config); | |
if ($this->upload->do_upload()) { | |
//If image upload in folder, set also this value in "$image_data". | |
$image_data = $this->upload->data(); | |
} | |
switch ($this->input->post("mode")) { | |
case "crop": | |
//"$image_data" contains information about upload image, so this array pass in function for manipulation. | |
$data = $this->crop($image_data); | |
$this->load->view('manipulation_view', $data); | |
break; | |
case "resize": | |
//"$image_data" contains information about upload image, so this array pass in function for manipulation. | |
$data = $this->resize($image_data); | |
$this->load->view('manipulation_view', $data); | |
break; | |
case "rotate": | |
//"$image_data" contains information about upload image, so this array pass in function for manipulation. | |
$data = $this->rotate($image_data); | |
$this->load->view('manipulation_view', $data); | |
break; | |
case "watermark": | |
//"$image_data" contains information about upload image, so this array pass in function for manipulation. | |
$data = $this->water_marking($image_data); | |
$this->load->view('manipulation_view', $data); | |
break; | |
default: | |
// If select no option in above given, then this will alert you message. | |
echo "<script type='text/javascript'> alert('Please Select any option which you want to operate'); </script>"; | |
$this->load->view('manipulation_view'); | |
break; | |
} | |
} | |
} | |
// Resize Manipulation. | |
public function resize($image_data) { | |
$img = substr($image_data['full_path'], 51); | |
$config['image_library'] = 'gd2'; | |
$config['source_image'] = $image_data['full_path']; | |
$config['new_image'] = './uploads/new_' . $img; | |
$config['width'] = $this->input->post('width'); | |
$config['height'] = $this->input->post('height'); | |
//send config array to image_lib's initialize function | |
$this->image_lib->initialize($config); | |
$src = $config['new_image']; | |
$data['new_image'] = substr($src, 2); | |
$data['img_src'] = base_url() . $data['new_image']; | |
// Call resize function in image library. | |
$this->image_lib->resize(); | |
// Return new image contains above properties and also store in "upload" folder. | |
return $data; | |
} | |
// Rotate Manipulation. | |
public function rotate($image_data) { | |
$img = substr($image_data['full_path'], 51); | |
$config['image_library'] = 'gd2'; | |
$config['source_image'] = $image_data['full_path']; | |
$config['rotation_angle'] = $this->input->post('degree'); | |
$config['quality'] = "90%"; | |
$config['new_image'] = './uploads/rot_' . $img; | |
//send config array to image_lib's initialize function | |
$this->image_lib->initialize($config); | |
$src = $config['new_image']; | |
$data['rot_image'] = substr($src, 2); | |
$data['rot_image'] = base_url() . $data['rot_image']; | |
// Call rotate function in image library. | |
$this->image_lib->rotate(); | |
// Return new image contains above properties and also store in "upload" folder. | |
return $data; | |
} | |
// Water Mark Manipulation. | |
public function water_marking($image_data) { | |
$img = substr($image_data['full_path'], 51); | |
$config['image_library'] = 'gd2'; | |
$config['source_image'] = $image_data['full_path']; | |
$config['wm_text'] = $this->input->post('text'); | |
$config['wm_type'] = 'text'; | |
$config['wm_font_path'] = './system/fonts/texb.ttf'; | |
$config['wm_font_size'] = '50'; | |
$config['wm_font_color'] = '#707A7C'; | |
$config['wm_hor_alignment'] = 'center'; | |
$config['new_image'] = './uploads/watermark_' . $img; | |
//send config array to image_lib's initialize function | |
$this->image_lib->initialize($config); | |
$src = $config['new_image']; | |
$data['watermark_image'] = substr($src, 2); | |
$data['watermark_image'] = base_url() . $data['watermark_image']; | |
// Call watermark function in image library. | |
$this->image_lib->watermark(); | |
// Return new image contains above properties and also store in "upload" folder. | |
return $data; | |
} | |
// Crop Manipulation. | |
public function crop($image_data) { | |
$img = substr($image_data['full_path'], 51); | |
$config['image_library'] = 'gd2'; | |
$config['source_image'] = $image_data['full_path']; | |
$config['x_axis'] = $this->input->post('x1'); | |
$config['y_axis'] = $this->input->post('y1'); | |
$config['maintain_ratio'] = TRUE; | |
$config['width'] = $this->input->post('width_cor'); | |
$config['height'] = $this->input->post('height_cor'); | |
$config['new_image'] = './uploads/crop_' . $img; | |
//send config array to image_lib's initialize function | |
$this->image_lib->initialize($config); | |
$src = $config['new_image']; | |
$data['crop_image'] = substr($src, 2); | |
$data['crop_image'] = base_url() . $data['crop_image']; | |
// Call crop function in image library. | |
$this->image_lib->crop(); | |
// Return new image contains above properties and also store in "upload" folder. | |
return $data; | |
} | |
} | |
?> | |
//v.03 | |
public function do_resize() | |
{ | |
$filename = $this->input->post('new_val'); | |
$source_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/tmp/' . $filename; | |
$target_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/'; | |
$config_manip = array( | |
'image_library' => 'gd2', | |
'source_image' => $source_path, | |
'new_image' => $target_path, | |
'maintain_ratio' => TRUE, | |
'create_thumb' => TRUE, | |
'thumb_marker' => '_thumb', | |
'width' => 150, | |
'height' => 150 | |
); | |
$this->load->library('image_lib', $config_manip); | |
if (!$this->image_lib->resize()) { | |
echo $this->image_lib->display_errors(); | |
} | |
// clear // | |
$this->image_lib->clear(); | |
} | |
//Date Save to Database | |
$data['tender_date'] = date("Y-m-d", strtotime(str_replace('/', '-', $this->input->post('tender_date')))); | |
...OR | |
date("Y-m-d h:i A", strtotime(str_replace('/', '-', $this->input->post('CLASS_START_TIME')))) | |
//Time Save to MySQL Database | |
date("h:i A", strtotime(str_replace('/', '-', $this->input->post('CLASS_END_TIME')))); | |
//Oracle Database | |
date("Y-m-d G:i:s", strtotime(str_replace('/', '-', $this->input->post('CLASS_START_TIME')))); | |
//Cookie | |
Syntax: set_cookie($name[, $value = ''[, $expire = ''[, $domain = ''[, $path = '/'[, $prefix = ''[, $secure = NULL[, $httponly = NULL]]]]]]]) | |
-> Set Cookie | |
$this->load->helper('cookie'); | |
$cookie = array( | |
'name' => 'the_cookie', | |
'value' => 'test value here', | |
'expire' => '15000000', | |
'secure' => FALSE, | |
'httponly' => TRUE, | |
); | |
$this->input->set_cookie($cookie); | |
-> Retrieve Cookie | |
$this->input->cookie('cookie_name', TRUE); //with xss filtering | |
$this->input->cookie('cookie_name'); //without xss filtering | |
OR | |
get_cookie($index[, $xss_clean = NULL]) | |
$cookieData = get_cookie("cookie_name"); | |
-> Delete Cookie | |
delete_cookie($name[, $domain = ''[, $path = '/'[, $prefix = '']]]) | |
i.e, | |
delete_cookie('name'); //All path | |
OR | |
delete_cookie($name, $domain, $path, $prefix); // For specific path | |
//Custom route | |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); | |
$route['default_controller'] = "home"; | |
$route['Pricing'] = "Pricing/index"; | |
///fixed routes | |
$route['Samples'] = "Samples/index"; | |
$route['Blog'] = "Blog/index"; | |
$route['Free_Trial'] = "Free_Trial/index"; | |
$route['Sing_in'] = "Sing_in/index"; | |
$route['Registation'] = "Registation/index"; | |
$route['My_account'] = "My_account/index"; | |
/////****Note to return home controller keep empty in href//// | |
/////**** $route['Sing_in'] use slash after Sign_in ////// | |
////dynamic routes | |
$route['([a-zA-Z0-9_-]+)'] = "Service_details/index/$1"; | |
$route['blog/([a-zA-Z0-9_-]+)'] = "Blog_details/index/$1"; | |
$route['404_override'] = ''; | |
/* End of file routes.php */ | |
/* Location: ./application/config/routes.php */ | |
?> | |
//Codeigniter WHERE AND OR together | |
$this->db->where("id",1)->where("(status='live' OR status='dead')"); | |
//Combining mysql AND OR queries in Codeigniter | |
$this->db->where("status","live")->or_where("status","dead"); | |
you can also use: | |
$this->db->where("(status='live' OR status='dead')"); | |
you can also use: | |
$this->db->where('LastName', 'Svendson'); | |
$this->db->where('Age', 12); | |
$this->db->where("(FirstName='Tove' OR FirstName='Ola' OR Gender='M' OR Country='India')", NULL, FALSE); | |
$query = $this->db->get('Persons'); | |
return $query->result(); | |
you can also use: | |
return $this->db | |
->where('LastName', 'Svendson'); | |
->where('Age', 12); | |
->group_start() | |
->where('FirstName','Tove') | |
->or_where('FirstName','Ola') | |
->or_where('Gender','M') | |
->or_where('Country','India') | |
->group_end() | |
->get('Persons') | |
->result(); | |
//Preview Data Structure | |
function pr($data) | |
{ | |
echo "<pre>"; | |
print_r($data); | |
exit; | |
} | |
//Find using orderby | |
function findAllByAttributeWithOrderBy($tableName, $attribute, $order_by_field_name, $order_by = 'ASC') { | |
return $this->db->order_by("CAST($order_by_field_name AS SIGNED)", "$order_by")->get_where($tableName, $attribute)->result(); | |
} | |
$data['trainingInst'] = $this->utilities->findAllByAttributeWithOrderBy("bn_traininginstitute", array('ACTIVE_STATUS'=>1), "Code","ASC"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment