<< BACK
Codeigniter setup with Mysql DB connection : DOWNLOAD
---------------------------------------------------------------------------------------------
Codeigniter setup with Mongo DB connection : DOWNLOAD
---------------------------------------------------------------------------------------------
Send Mail :
//load email library
$this->load->library('email');
//Attachment
for($i=0;$i<count($attachFile);$i++){
$cond_l = $attachFile[$i];
$file = "./uploads/sendMailDoc/$cond_l";
$this->email->attach($file);
}
$print_debugger = "message";
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['protocol'] = 'sendmail';
$this->email->initialize($config);
$message = $print_debugger;
$message= wordwrap($message);
$subject= "Test to send mail.";
$this->email->from('test@test.com', 'Email Error');
$this->email->to('abc@gmail.com');
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
---------------------------------------------------------------------------------------------
Model :
$this->db->insert($tablename, $formValues);
if($this->db->affected_rows() == 1){
return True;
} else {
return False;
}
}
$this->db->insert($tbl,$val);
$data = $this->db->insert_id();
return $data;
}
$this->db->where($ID, $val[$ID]);
$this->db->update($tbl_name, $val);
if($this->db->affected_rows() == 1){
return True;
} else {
return False;
}
}
$this->db->where($ID_TNM, $ID);
$this->db->delete($tbl_name);
}
$query = $this->db->query("SELECT * FROM $tbl $order_by");
$result = $query->result_array();
return $result;
}
$row = $this->db->get_where($tbl, array($clm => $val))->result_array();
return $row;
}
$contact = $this->db->select('*')->get_where($tbl, array($clm1 => $val1,$clm2 => $val2))->result_array();
return $contact;
}
$query = $this->db->query("SELECT * FROM $tbl_name where $fld_name = '$unit_name'");
if ($query->num_rows() == 0) {
return 0;
} else {
return 1;
}
}
$query = $this->db->query("SELECT * FROM $tbl_name where $fld_name = '$unit_name' and $fld_id != '$id'");
if ($query->num_rows() == 0) {
return 0;
} else {
return 1;
}
}
---------------------------------------------------------------------------------------------
Controllers :
$data['nav_dashboard'] = 'active';
$data['main_content'] = 'home/dashboard/dashboard_view';
$this->load->view('includes/home/template', $data);
}
Function in Controller (Insert Data)
function userLogin(){
$login_email = $this->input->post('login_email');
$password = $this->input->post('login_password');
$emailExplode = explode('@',$login_email);
for($i=0;$i<count($emailExplode);$i++){
$emailCount += $i;
}
if($emailCount != 0){
$checkStatus = $this->home_model->userLogin('emailid','password','status',$login_email,$password,"1");
} else if($emailCount == 0){
$checkStatus = $this->home_model->userLogin('mobilenumber','password','status',$login_email,$password,"1");
}
if ($checkStatus) {
$data = array(
'user_id' => $checkStatus[0]['user_id'],
'firstname' => $checkStatus[0]['firstname'],
'section_id' => $checkStatus[0]['section_id']
);
$this->session->set_userdata($data);
echo '0';
} else {
echo "<span style='color : red;'>Please Enter Valid User Name & Password.</span>";
}
}
function showData(){
$data['main_content'] = 'home/about_us';
$this->load->view('home/includes/template', $data);
}
function inserData(){
$user_id = $this->session->userdata('user_id');
$full_name = $this->input->post('full_name');
$date_time = gmdate("m/d/Y h:i:s");
$ip = $this->input->ip_address();
$member = array(
"full_name" => $full_name,
"user_id" => $user_id,
"upload_time" => $date_time,
"ip" => $ip
);
$connection = 'insert_table';
$user_id = $this->home_model->tableInsert($connection,$member);
}
}
function logout(){
//unset the seesion
$array_items = array('user_id'=>'', 'firstname'=>'', 'emailid'=>'');
$this->session->unset_userdata($array_items);
$this->session->sess_destroy();
redirect(base_url().'home');
}
template.php
$this->load->view('includes/header');
$this->load->view($main_content);
$this->load->view('includes/footer');
---------------------------------------------------------------------------------------------
Config file :
Set the session :
---------------------------------------------------------------------------------------------
.htaccess file:
RewriteBase /projectName/
RewriteCond $1 !^(images|stylesheets|javascript)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /projectName/index.php?/$1 [L]
---------------------------------------------------------------------------------------------
Codeigniter setup with Mysql DB connection : DOWNLOAD
---------------------------------------------------------------------------------------------
Codeigniter setup with Mongo DB connection : DOWNLOAD
---------------------------------------------------------------------------------------------
Send Mail :
//load email library
$this->load->library('email');
//Attachment
for($i=0;$i<count($attachFile);$i++){
$cond_l = $attachFile[$i];
$file = "./uploads/sendMailDoc/$cond_l";
$this->email->attach($file);
}
$print_debugger = "message";
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['protocol'] = 'sendmail';
$this->email->initialize($config);
$message = $print_debugger;
$message= wordwrap($message);
$subject= "Test to send mail.";
$this->email->from('test@test.com', 'Email Error');
$this->email->to('abc@gmail.com');
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
---------------------------------------------------------------------------------------------
Model :
Class Home_model extends CI_Model{
function __construct() {
parent::__construct();
}
}
- Data insert into table :
$this->db->insert($tablename, $formValues);
if($this->db->affected_rows() == 1){
return True;
} else {
return False;
}
}
- Data insert into table and return id :
$this->db->insert($tbl,$val);
$data = $this->db->insert_id();
return $data;
}
- Update Data :
$this->db->where($ID, $val[$ID]);
$this->db->update($tbl_name, $val);
if($this->db->affected_rows() == 1){
return True;
} else {
return False;
}
}
- Delete Data :
$this->db->where($ID_TNM, $ID);
$this->db->delete($tbl_name);
}
- Get Table ALL Record :
$query = $this->db->query("SELECT * FROM $tbl $order_by");
$result = $query->result_array();
return $result;
}
- Get Single Record :
$row = $this->db->get_where($tbl, array($clm => $val))->result_array();
return $row;
}
- Get Two Record :
$contact = $this->db->select('*')->get_where($tbl, array($clm1 => $val1,$clm2 => $val2))->result_array();
return $contact;
}
- Check record present in table insert time :
$query = $this->db->query("SELECT * FROM $tbl_name where $fld_name = '$unit_name'");
if ($query->num_rows() == 0) {
return 0;
} else {
return 1;
}
}
- Check record present in table update time :
$query = $this->db->query("SELECT * FROM $tbl_name where $fld_name = '$unit_name' and $fld_id != '$id'");
if ($query->num_rows() == 0) {
return 0;
} else {
return 1;
}
}
---------------------------------------------------------------------------------------------
Controllers :
- Create Controllers(e.g. controller name = test.php) :
function __construct() {
function index(){parent::__construct();
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
$this->no_cache();
$this->load->model('home_model');
$user_id = $this->session->userdata('user_id');
if(empty($user_id)){
redirect(base_url());
}
}
protected function no_cache() {
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
}
$data['nav_dashboard'] = 'active';
$data['main_content'] = 'home/dashboard/dashboard_view';
$this->load->view('includes/home/template', $data);
}
Function in Controller (Insert Data)
function userLogin(){
$login_email = $this->input->post('login_email');
$password = $this->input->post('login_password');
$emailExplode = explode('@',$login_email);
for($i=0;$i<count($emailExplode);$i++){
$emailCount += $i;
}
if($emailCount != 0){
$checkStatus = $this->home_model->userLogin('emailid','password','status',$login_email,$password,"1");
} else if($emailCount == 0){
$checkStatus = $this->home_model->userLogin('mobilenumber','password','status',$login_email,$password,"1");
}
if ($checkStatus) {
$data = array(
'user_id' => $checkStatus[0]['user_id'],
'firstname' => $checkStatus[0]['firstname'],
'section_id' => $checkStatus[0]['section_id']
);
$this->session->set_userdata($data);
echo '0';
} else {
echo "<span style='color : red;'>Please Enter Valid User Name & Password.</span>";
}
}
function showData(){
$data['main_content'] = 'home/about_us';
$this->load->view('home/includes/template', $data);
}
function inserData(){
$user_id = $this->session->userdata('user_id');
$full_name = $this->input->post('full_name');
$date_time = gmdate("m/d/Y h:i:s");
$ip = $this->input->ip_address();
$member = array(
"full_name" => $full_name,
"user_id" => $user_id,
"upload_time" => $date_time,
"ip" => $ip
);
$connection = 'insert_table';
$user_id = $this->home_model->tableInsert($connection,$member);
}
}
function logout(){
//unset the seesion
$array_items = array('user_id'=>'', 'firstname'=>'', 'emailid'=>'');
$this->session->unset_userdata($array_items);
$this->session->sess_destroy();
redirect(base_url().'home');
}
template.php
$this->load->view('includes/header');
$this->load->view($main_content);
$this->load->view('includes/footer');
---------------------------------------------------------------------------------------------
Config file :
- config.php :
$config['base_url'] ="http://localhost/projectName/";$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-!()?+=/$#@&^!<>"';$config['encryption_key'] = '123456';
- autoload.php :
$autoload['packages'] = array(APPPATH.'third_party');$autoload['libraries'] = array('database', 'form_validation', 'pagination','session','table','email');$autoload['helper'] = array('url','form','string','file','html','date','text','email');
- database.php
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'databaseName';
- routes.php
$route['default_controller'] = "home";---------------------------------------------------------------------------------------------
Set the session :
$data_session = array(
'user_id' => $user_id,
'username' => $username,
'fullname' => $fullname,
'emailid' => $emailid
);
$this->session->set_userdata($data_session);
---------------------------------------------------------------------------------------------
Unset the session (destroy):'user_id' => $user_id,
'username' => $username,
'fullname' => $fullname,
'emailid' => $emailid
);
$this->session->set_userdata($data_session);
---------------------------------------------------------------------------------------------
$array_items = array('user_id' =>'', 'firstname'=>'', 'emailid'=>'');
$this->session->unset_userdata($array_items);
$this->session->sess_destroy();
---------------------------------------------------------------------------------------------
.htaccess file:
RewriteEngine OnRewriteBase /projectName/
RewriteCond $1 !^(images|stylesheets|javascript)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /projectName/index.php?/$1 [L]
---------------------------------------------------------------------------------------------
Ajax :
$( ".returned" ).click(function() {
var returned_id = $(this).val();
var notice_id = $(this).attr("NI");
var document_transfer_id = $(this).attr("dti");
$.ajax({
url: "<?php echo base_url(); ?>notice/getReturnedUpdateDocumentTransfer",
type: 'POST',
data: 'returned=' + returned_id + "&document_transfer_id=" + document_transfer_id ,
success: function(msg) {
$('#documentTransferDiv').html(msg);
}
});
});
});
OR
$(document).ready(function(){
$( ".returned" ).click(function() {
$.post("<?php echo base_url();?>notice/getReturnedUpdateDocumentTransfer", { returned:returned_id, document_transfer_id:document_transfer_id },function(data){
$('#documentTransferDiv').html(data);
});
});
});
//click base to function
function Get_primary_Email_Data(id){
var Email_Data = 'Email_ID=' + id;
$.ajax({
url: "<?php echo base_url(); ?>home/get_email_address",
type: 'POST',
data: Email_Data,
success: function(msg) {
$('#PRIMARY_EMAIL').val(msg);
}
});
}
- Click Event :
//click base to class
$(document).ready(function(){$( ".returned" ).click(function() {
var returned_id = $(this).val();
var notice_id = $(this).attr("NI");
var document_transfer_id = $(this).attr("dti");
$.ajax({
url: "<?php echo base_url(); ?>notice/getReturnedUpdateDocumentTransfer",
type: 'POST',
data: 'returned=' + returned_id + "&document_transfer_id=" + document_transfer_id ,
success: function(msg) {
$('#documentTransferDiv').html(msg);
}
});
});
});
OR
$(document).ready(function(){
$( ".returned" ).click(function() {
$.post("<?php echo base_url();?>notice/getReturnedUpdateDocumentTransfer", { returned:returned_id, document_transfer_id:document_transfer_id },function(data){
$('#documentTransferDiv').html(data);
});
});
});
//click base to function
function Get_primary_Email_Data(id){
var Email_Data = 'Email_ID=' + id;
$.ajax({
url: "<?php echo base_url(); ?>home/get_email_address",
type: 'POST',
data: Email_Data,
success: function(msg) {
$('#PRIMARY_EMAIL').val(msg);
}
});
}
- Press To Enter Event :
$(document).ready(function(){
$('.search_txtbox1').keypress(function(e) {
if(e.which == 13) {
var txtCuisine1=$('#txtCuisine1').val();
var txtCuisine2=$('#txtCuisine2').val();
if(txtCuisine1.length == 0) { //for checking 3 characters
$('#restaurant_search_result').html("");
}
$('#restaurant_search_result').html("");
//loading image
$('#restaurant_search_result').html('<center><img src="<?php echo base_url(); ?>images/progress.gif"/></center>');
$.ajax({
url: "<?php echo base_url(); ?>pilot/restaurant_search_details",
type: 'POST',
data: 'cuisine1='+txtCuisine1+'&cuisine2='+txtCuisine2,
success: function(msg) {
$('#restaurant_search_result').html(msg);
}
});
}
});
});
- On Key Up Event :
$(document).ready(function(){
$(".search_txtbox1").keyup(function(){
var txtCuisine1=$('#txtCuisine1').val();
var txtCuisine2=$('#txtCuisine2').val();
if(txtCuisine1.length == 0) { //for checking 3 characters
$('#restaurant_search_result').html("");
}
$('#restaurant_search_result').html("");
//loading image
$('#restaurant_search_result').html('<center><img src="<?php echo base_url(); ?>images/progress.gif"/></center>');
$.ajax({
url: "<?php echo base_url(); ?>pilot/restaurant_search_details",
type: 'POST',
data: 'cuisine1='+txtCuisine1+'&cuisine2='+txtCuisine2,
success: function(msg) {
$('#restaurant_search_result').html(msg);
}
});
});
});
---------------------------------------------------------------------------------------------
Install ffmpeg in window:
Refer Link:
http://ffmpeg.zeranoe.com/builds/
righthand site first option extract and rename as ffmpeg in c drive
And then follow this image
---------------------------------------------------------------------------------------------
Upload Video File Then Create Thumb :
//first install ffmpeg
$videoVal = "abc.mp4";
move_uploaded_file($_FILES["uploadFile"]["tmp_name"],"images/uploadFile/" . $videoVal);
$ffmpeg = 'ffmpeg';
$video = 'images/uploadFile/'.$videoVal;
$imagename_check = explode(".",$videoVal);
$nameof_img = $imagename_check[0];
$image = 'images/uploadFile/thumb/'.$nameof_img.'.png';
$second = 5;
// get the duration and a random place within that
$cmd = "$ffmpeg -i $video 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}
---------------------------------------------------------------------------------------------
Upload Image File Then Create Thumb:
$imageVal = "abc.jpg";
move_uploaded_file($_FILES["uploadFile"]["tmp_name"],"images/uploadFile/" . $imageVal);
$this->load->library('image_lib');
$img_cfg['image_library'] = 'gd2';
$img_cfg['source_image'] = "images/".$imageVal;
$img_cfg['maintain_ratio'] = TRUE;
$img_cfg['new_image'] = "images/thumb/".$imageVal;
$img_cfg['width'] = 120;
$img_cfg['quality'] = 100;
$img_cfg['height'] = 120;
$this->image_lib->initialize($img_cfg);
$this->image_lib->resize();
---------------------------------------------------------------------------------------------
Upload Image File Then Crop Image:
function croptheimage(){
$imagename = "hP5R8dCjb41452146749_01_07_2016_07_05_49_image.png";
$this->load->library('image_lib');
$this->image_lib->initialize($image_config);
$image_Path= './images/snapshot/screenshots/'.$imagename;
$send_path = './rajeshDownload/crop/'.$imagename;
$image_config['image_library'] = 'gd2';
$image_config['source_image'] = $image_Path;
$image_config['new_image'] = $send_path;
$image_config['quality'] = "100%";
$image_config['maintain_ratio'] = FALSE;
$image_config['width'] = 610;
$image_config['height'] = 300;
$image_config['x_axis'] = '300';
$image_config['y_axis'] = '19';
$this->image_lib->initialize($image_config);
if (!$this->image_lib->crop()){
echo 'error here';
} else {
echo "success";
}
}
---------------------------------------------------------------------------------------------
Upload Video/Image Then Get Width-Height And Other Property:
Refer Link:
http://stackoverflow.com/questions/4847752/how-to-get-video-duration-dimension-and-size-in-php //for video property
Video
$ffmpeg = 'ffmpeg';
$video ='images/abc.mp4';
function _get_video_attributes($video, $ffmpeg) {
$command = $ffmpeg . ' -i ' . $video . ' -vstats 2>&1';
$output = shell_exec($command);
$newstring = str_replace("tv,", "tv_", $output);
$regex_sizes = "/Video: ([^,]*), ([^,]*), ([0-9]{1,4})x([0-9]{1,4})/";
if (preg_match($regex_sizes, $newstring, $regs)) {
$codec = $regs [1] ? $regs [1] : null;
$width = $regs [3] ? $regs [3] : null;
$height = $regs [4] ? $regs [4] : null;
}
$regex_duration = "/Duration: ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}).([0-9]{1,2})/";
if (preg_match($regex_duration, $newstring, $regs)) {
$hours = $regs [1] ? $regs [1] : null;
$mins = $regs [2] ? $regs [2] : null;
$secs = $regs [3] ? $regs [3] : null;
$ms = $regs [4] ? $regs [4] : null;
}
$returnArray = array (
'codec' => $codec,
'width' => $width,
'height' => $height,
'hours' => $hours,
'mins' => $mins,
'secs' => $secs,
'ms' => $ms
);
return $returnArray;
}
$video_attributes = $this->_get_video_attributes($video, $ffmpeg);
$videoWidth = $video_attributes['width'];
$videoHeigth = $video_attributes['height'];
*****************************************************************
Image
$imgPath = "images/uploadFile/abc.jpg";
$imagedetails = getimagesize($imgPath);
$videoWidth = $imagedetails[0];
$videoHeigth = $imagedetails[1];
---------------------------------------------------------------------------------------------
Upload File Other Server Without Using FTP:
function uploadServerData(){
//Upload to the local server
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
if($this->upload->do_upload('file')){
//Get uploaded file information
$upload_data = $this->upload->data();
$fileName = $upload_data['file_name'];
//File path at local server
$source = 'uploads/'.$fileName;
//Load codeigniter FTP class
$this->load->library('ftp');
//FTP configuration
$ftp_config['hostname'] = '192.168.1.100';
$ftp_config['username'] = 'developer';
$ftp_config['password'] = '123';
$ftp_config['debug'] = TRUE;
//Connect to the remote server
$this->ftp->connect($ftp_config);
//File upload path of remote server
$destination = './otherServerFolder/images/test/'.$fileName;
//Upload file to the remote server
$this->ftp->upload($source, ".".$destination);
//Close FTP connection
$this->ftp->close();
//Delete file from local server
@unlink($source);
}
}
---------------------------------------------------------------------------------------------
Create Unique Folder Using PHP:
$eventDate = date("Y-m-d");
$date_folder=str_replace("-", "_", $eventDate);
$dirPath ='images/uploadFile/'.$date_folder;
if(!is_dir($dirPath)) { //create the folder if it's not already exists
mkdir($dirPath,0777,TRUE);
}
$dirPath_thumb = 'images/uploadFile/thumb/'.$date_folder;
if(!is_dir($dirPath_thumb)) { //create the folder if it's not already exists
mkdir($dirPath_thumb,0777,TRUE);
}
---------------------------------------------------------------------------------------------
Get Two Different Database Access In Codeigniter:
In database file changes
$active_group = 'default';
$active_record = TRUE;
//first database details
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'firstDatabse';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
//second database details
$db['write']['hostname'] = "192.168.1.1";
$db['write']['username'] = "root";
$db['write']['password'] = "";
$db['write']['database'] = "secondDatabse";
$db['write']['dbdriver'] = "mysql";
$db['write']['dbprefix'] = "";
$db['write']['pconnect'] = TRUE;
$db['write']['db_debug'] = TRUE;
$db['write']['cache_on'] = FALSE;
$db['write']['cachedir'] = "";
$db['write']['char_set'] = "utf8";
$db['write']['dbcollat'] = "utf8_general_ci";
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
When access second database Write Model function:
function List_All_Select_Data_($tbl){
$read_db = $this->load->database('write', TRUE);
$query = $read_db->query("SELECT * FROM $tbl");
$result = $query->result_array();
return $result;
}
---------------------------------------------------------------------------------------------
Create Unique Folder Using PHP:
$eventDate = date("Y-m-d");
$date_folder=str_replace("-", "_", $eventDate);
$dirPath ='images/uploadFile/'.$date_folder;
if(!is_dir($dirPath)) { //create the folder if it's not already exists
mkdir($dirPath,0777,TRUE);
}
$dirPath_thumb = 'images/uploadFile/thumb/'.$date_folder;
if(!is_dir($dirPath_thumb)) { //create the folder if it's not already exists
mkdir($dirPath_thumb,0777,TRUE);
}
---------------------------------------------------------------------------------------------
Send Email By SMTP in PHP (phpmailer):
Download email file and store view folder
https://goo.gl/zMz4J7
In Controller
function email_home(){
$this->load->view("email/class.phpmailer.php");
}
function sendemail(){
$file = "./images/test.jpg";
$emailid = "to@gmail.com";
$cc = "cc@gmail.com";
$bcc = "bcc@gmail.com";
$msg = "Hiii";
$this->email_home(); // include the class name
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587 465
$mail->IsHTML(true);
$mail->Username = "abc@gmail.com";
$mail->Password = "*****";
$mail->SetFrom("abc@gmail.com");
$mail->Subject = "Test Mail";
$mail->Body = $msg;
$mail->AddAddress($emailid);
$mail->AddCC($cc);
$mail->AddBCC($bcc);
$mail->AddAttachment($file);
$mail->Send();
}
---------------------------------------------------------------------------------------------
Play Video Or Image Sequence In PHP :
/*
Table structure of video/image play
CREATE TABLE `pp_shedule_play_details` (
`set_play_id` int(11) NOT NULL AUTO_INCREMENT,
`play_type` int(5) DEFAULT NULL, //1=video, 2=image
`play_name` varchar(3000) DEFAULT NULL, //video1.mp4,video2.jpg
`time_duration` varchar(200) DEFAULT NULL, //1sec = 1000ms
`video_image_width` varchar(2000) DEFAULT NULL, //width = 1280
`video_image_heigth` varchar(2000) DEFAULT NULL, //heigth = 720
`sequence_number` int(11) DEFAULT NULL, //1,2
`mute` enum('0','1') DEFAULT '1' COMMENT '1->unmute, 0->mute',
`upload_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`status` enum('0','1') DEFAULT '1' COMMENT '1->active, 0->inactive',
`ip` varchar(100) DEFAULT NULL,
PRIMARY KEY (`set_play_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1
insert into `pp_shedule_play_details`(`set_play_id`,`play_type`,`play_name`,`time_duration`,`video_image_width`,`video_image_heigth`,`sequence_number`,`mute`,`upload_date`,`status`,`ip`)
values
(1,2,'video1.jpg','5000','1024','768',1,'1','2015-12-31 14:49:42','1','192.168.1.1'),
(2,2,'video2.jpg','7000','1024','768',2,'1','2015-12-31 14:49:42','1','192.168.1.1'),
(3,2,'video3.JPG','8000','1024','768',3,'1','2015-12-31 14:49:42','1','192.168.1.1'),
(4,1,'video4.mp4','2000','480','360',4,'1','2015-12-31 14:47:15','1','192.168.1.1');
*/
<!--PlayDataCount is count of all videos/images-->
<input type="hidden" value="5" name="playDataCount" id="playDataCount" />
<!--First Time Hidden All Video And Images-->
<video class="center-block " id="player1" style="display:none;" controls autoplay onended="runVideo();" >
<source src="<?php echo base_url(); ?>images/uploadFile/video1.mp4" type="video/mp4"/>
</video>
<img class="center-block mrgn_sp" style="display:none; " controls loop src="<?php echo base_url(); ?>images/uploadFile/vedio1.jpg" id="LoadDiv"/>
<?PHP $playType = $playData[0]['play_type']; //this value is return from database and base on this value you get which type is load ?>
<script>
$(document).ready(function () {
if ("<?PHP echo $playType ; ?>" == 2) { //if load image first time
//var duration_S = '<?PHP echo $playData[0]['time_duration']; ?>';
setTimeout(function () {
$('#LoadDiv').show();
$('#player1').hide();
runVideo();
}, 200);
} else if ("<?PHP echo $playType; ?>" == 1) { //if load video first time
$('#LoadDiv').hide();
$('#player1').show();
document.body.addEventListener('click', function (e) {
var target = e.target;
if (target.nodeName == 'VIDEO') { // or EMBED
target.style.position = 'absolute';
target.style.width = '100%';
target.style.height = '100%';
}
}, false);
}
});
var video_count = 1;
function runVideo() {
var playDataCounts = $('#playDataCount').val();
if (parseInt(playDataCounts) <= parseInt(video_count)) {
video_count = 1;
} else {
video_count++;
}
var datastring = 'id=' + video_count;
$.ajax({
//ajax function they return time duration of current video or image and play_type_id of next video or image
url: "<?php echo base_url(); ?>video/getScheduleVideoTableDataType",
type: 'POST',
data: datastring,
success: function (msg) {
var fields = msg.split("==");
var play_type_id = fields[0]; //1=video, 2=image
var extention = fields[1];
var duration = fields[2]; //1sec = 1000ms
var muteStatus = fields[3]; //0=mute, 1=unmute
if (play_type_id == 1) {
setTimeout(function () {
$('#player1').show();
$('#LoadDiv').hide();
videoPlayer = document.getElementById("player1");
if (muteStatus == '0') {
videoPlayer.muted = true;
}
var nextVideo = "<?php echo base_url(); ?>images/uploadFile/video" + video_count + ".mp4";
videoPlayer.src = nextVideo;
videoPlayer.play();
videoPlayer.muted = false;
}, duration);
} else if (play_type_id == 2) {
setTimeout(function () {
$('#player1').hide();
$('#LoadDiv').show();
imageShow = document.getElementById("LoadDiv");
if (muteStatus == '0') {
imageShow.muted = true;
}
var nextImage = "<?php echo base_url(); ?>images/uploadFile/video" + video_count + "." + extention;
imageShow.src = nextImage;
runVideo();
}, duration);
}
}
});
}
</script>
---------------------------------------------------------------------------------------------
Call method(function) one controller to onother controller:
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
Install ffmpeg in window:
Refer Link:
http://ffmpeg.zeranoe.com/builds/
righthand site first option extract and rename as ffmpeg in c drive
And then follow this image
---------------------------------------------------------------------------------------------
Upload Video File Then Create Thumb :
//first install ffmpeg
$videoVal = "abc.mp4";
move_uploaded_file($_FILES["uploadFile"]["tmp_name"],"images/uploadFile/" . $videoVal);
$ffmpeg = 'ffmpeg';
$video = 'images/uploadFile/'.$videoVal;
$imagename_check = explode(".",$videoVal);
$nameof_img = $imagename_check[0];
$image = 'images/uploadFile/thumb/'.$nameof_img.'.png';
$second = 5;
// get the duration and a random place within that
$cmd = "$ffmpeg -i $video 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}
---------------------------------------------------------------------------------------------
Upload Image File Then Create Thumb:
$imageVal = "abc.jpg";
move_uploaded_file($_FILES["uploadFile"]["tmp_name"],"images/uploadFile/" . $imageVal);
$this->load->library('image_lib');
$img_cfg['image_library'] = 'gd2';
$img_cfg['source_image'] = "images/".$imageVal;
$img_cfg['maintain_ratio'] = TRUE;
$img_cfg['new_image'] = "images/thumb/".$imageVal;
$img_cfg['width'] = 120;
$img_cfg['quality'] = 100;
$img_cfg['height'] = 120;
$this->image_lib->initialize($img_cfg);
$this->image_lib->resize();
---------------------------------------------------------------------------------------------
Upload Image File Then Crop Image:
function croptheimage(){
$imagename = "hP5R8dCjb41452146749_01_07_2016_07_05_49_image.png";
$this->load->library('image_lib');
$this->image_lib->initialize($image_config);
$image_Path= './images/snapshot/screenshots/'.$imagename;
$send_path = './rajeshDownload/crop/'.$imagename;
$image_config['image_library'] = 'gd2';
$image_config['source_image'] = $image_Path;
$image_config['new_image'] = $send_path;
$image_config['quality'] = "100%";
$image_config['maintain_ratio'] = FALSE;
$image_config['width'] = 610;
$image_config['height'] = 300;
$image_config['x_axis'] = '300';
$image_config['y_axis'] = '19';
$this->image_lib->initialize($image_config);
if (!$this->image_lib->crop()){
echo 'error here';
} else {
echo "success";
}
}
---------------------------------------------------------------------------------------------
Upload Video/Image Then Get Width-Height And Other Property:
Refer Link:
http://stackoverflow.com/questions/4847752/how-to-get-video-duration-dimension-and-size-in-php //for video property
Video
$ffmpeg = 'ffmpeg';
$video ='images/abc.mp4';
function _get_video_attributes($video, $ffmpeg) {
$command = $ffmpeg . ' -i ' . $video . ' -vstats 2>&1';
$output = shell_exec($command);
$newstring = str_replace("tv,", "tv_", $output);
$regex_sizes = "/Video: ([^,]*), ([^,]*), ([0-9]{1,4})x([0-9]{1,4})/";
if (preg_match($regex_sizes, $newstring, $regs)) {
$codec = $regs [1] ? $regs [1] : null;
$width = $regs [3] ? $regs [3] : null;
$height = $regs [4] ? $regs [4] : null;
}
$regex_duration = "/Duration: ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}).([0-9]{1,2})/";
if (preg_match($regex_duration, $newstring, $regs)) {
$hours = $regs [1] ? $regs [1] : null;
$mins = $regs [2] ? $regs [2] : null;
$secs = $regs [3] ? $regs [3] : null;
$ms = $regs [4] ? $regs [4] : null;
}
$returnArray = array (
'codec' => $codec,
'width' => $width,
'height' => $height,
'hours' => $hours,
'mins' => $mins,
'secs' => $secs,
'ms' => $ms
);
return $returnArray;
}
$video_attributes = $this->_get_video_attributes($video, $ffmpeg);
$videoWidth = $video_attributes['width'];
$videoHeigth = $video_attributes['height'];
*****************************************************************
Image
$imgPath = "images/uploadFile/abc.jpg";
$imagedetails = getimagesize($imgPath);
$videoWidth = $imagedetails[0];
$videoHeigth = $imagedetails[1];
---------------------------------------------------------------------------------------------
Upload File Other Server Without Using FTP:
function uploadServerData(){
//Upload to the local server
$config['upload_path'] = 'uploads/';
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
if($this->upload->do_upload('file')){
//Get uploaded file information
$upload_data = $this->upload->data();
$fileName = $upload_data['file_name'];
//File path at local server
$source = 'uploads/'.$fileName;
//Load codeigniter FTP class
$this->load->library('ftp');
//FTP configuration
$ftp_config['hostname'] = '192.168.1.100';
$ftp_config['username'] = 'developer';
$ftp_config['password'] = '123';
$ftp_config['debug'] = TRUE;
//Connect to the remote server
$this->ftp->connect($ftp_config);
//File upload path of remote server
$destination = './otherServerFolder/images/test/'.$fileName;
//Upload file to the remote server
$this->ftp->upload($source, ".".$destination);
//Close FTP connection
$this->ftp->close();
//Delete file from local server
@unlink($source);
}
}
---------------------------------------------------------------------------------------------
Create Unique Folder Using PHP:
$eventDate = date("Y-m-d");
$date_folder=str_replace("-", "_", $eventDate);
$dirPath ='images/uploadFile/'.$date_folder;
if(!is_dir($dirPath)) { //create the folder if it's not already exists
mkdir($dirPath,0777,TRUE);
}
$dirPath_thumb = 'images/uploadFile/thumb/'.$date_folder;
if(!is_dir($dirPath_thumb)) { //create the folder if it's not already exists
mkdir($dirPath_thumb,0777,TRUE);
}
---------------------------------------------------------------------------------------------
Get Two Different Database Access In Codeigniter:
In database file changes
$active_group = 'default';
$active_record = TRUE;
//first database details
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'firstDatabse';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
//second database details
$db['write']['hostname'] = "192.168.1.1";
$db['write']['username'] = "root";
$db['write']['password'] = "";
$db['write']['database'] = "secondDatabse";
$db['write']['dbdriver'] = "mysql";
$db['write']['dbprefix'] = "";
$db['write']['pconnect'] = TRUE;
$db['write']['db_debug'] = TRUE;
$db['write']['cache_on'] = FALSE;
$db['write']['cachedir'] = "";
$db['write']['char_set'] = "utf8";
$db['write']['dbcollat'] = "utf8_general_ci";
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
When access second database Write Model function:
function List_All_Select_Data_($tbl){
$read_db = $this->load->database('write', TRUE);
$query = $read_db->query("SELECT * FROM $tbl");
$result = $query->result_array();
return $result;
}
---------------------------------------------------------------------------------------------
Create Unique Folder Using PHP:
$eventDate = date("Y-m-d");
$date_folder=str_replace("-", "_", $eventDate);
$dirPath ='images/uploadFile/'.$date_folder;
if(!is_dir($dirPath)) { //create the folder if it's not already exists
mkdir($dirPath,0777,TRUE);
}
$dirPath_thumb = 'images/uploadFile/thumb/'.$date_folder;
if(!is_dir($dirPath_thumb)) { //create the folder if it's not already exists
mkdir($dirPath_thumb,0777,TRUE);
}
---------------------------------------------------------------------------------------------
Send Email By SMTP in PHP (phpmailer):
Download email file and store view folder
https://goo.gl/zMz4J7
In Controller
function email_home(){
$this->load->view("email/class.phpmailer.php");
}
function sendemail(){
$file = "./images/test.jpg";
$emailid = "to@gmail.com";
$cc = "cc@gmail.com";
$bcc = "bcc@gmail.com";
$msg = "Hiii";
$this->email_home(); // include the class name
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587 465
$mail->IsHTML(true);
$mail->Username = "abc@gmail.com";
$mail->Password = "*****";
$mail->SetFrom("abc@gmail.com");
$mail->Subject = "Test Mail";
$mail->Body = $msg;
$mail->AddAddress($emailid);
$mail->AddCC($cc);
$mail->AddBCC($bcc);
$mail->AddAttachment($file);
$mail->Send();
}
---------------------------------------------------------------------------------------------
Play Video Or Image Sequence In PHP :
/*
Table structure of video/image play
CREATE TABLE `pp_shedule_play_details` (
`set_play_id` int(11) NOT NULL AUTO_INCREMENT,
`play_type` int(5) DEFAULT NULL, //1=video, 2=image
`play_name` varchar(3000) DEFAULT NULL, //video1.mp4,video2.jpg
`time_duration` varchar(200) DEFAULT NULL, //1sec = 1000ms
`video_image_width` varchar(2000) DEFAULT NULL, //width = 1280
`video_image_heigth` varchar(2000) DEFAULT NULL, //heigth = 720
`sequence_number` int(11) DEFAULT NULL, //1,2
`mute` enum('0','1') DEFAULT '1' COMMENT '1->unmute, 0->mute',
`upload_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`status` enum('0','1') DEFAULT '1' COMMENT '1->active, 0->inactive',
`ip` varchar(100) DEFAULT NULL,
PRIMARY KEY (`set_play_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1
insert into `pp_shedule_play_details`(`set_play_id`,`play_type`,`play_name`,`time_duration`,`video_image_width`,`video_image_heigth`,`sequence_number`,`mute`,`upload_date`,`status`,`ip`)
values
(1,2,'video1.jpg','5000','1024','768',1,'1','2015-12-31 14:49:42','1','192.168.1.1'),
(2,2,'video2.jpg','7000','1024','768',2,'1','2015-12-31 14:49:42','1','192.168.1.1'),
(3,2,'video3.JPG','8000','1024','768',3,'1','2015-12-31 14:49:42','1','192.168.1.1'),
(4,1,'video4.mp4','2000','480','360',4,'1','2015-12-31 14:47:15','1','192.168.1.1');
*/
<!--PlayDataCount is count of all videos/images-->
<input type="hidden" value="5" name="playDataCount" id="playDataCount" />
<!--First Time Hidden All Video And Images-->
<video class="center-block " id="player1" style="display:none;" controls autoplay onended="runVideo();" >
<source src="<?php echo base_url(); ?>images/uploadFile/video1.mp4" type="video/mp4"/>
</video>
<img class="center-block mrgn_sp" style="display:none; " controls loop src="<?php echo base_url(); ?>images/uploadFile/vedio1.jpg" id="LoadDiv"/>
<?PHP $playType = $playData[0]['play_type']; //this value is return from database and base on this value you get which type is load ?>
<script>
$(document).ready(function () {
if ("<?PHP echo $playType ; ?>" == 2) { //if load image first time
//var duration_S = '<?PHP echo $playData[0]['time_duration']; ?>';
setTimeout(function () {
$('#LoadDiv').show();
$('#player1').hide();
runVideo();
}, 200);
} else if ("<?PHP echo $playType; ?>" == 1) { //if load video first time
$('#LoadDiv').hide();
$('#player1').show();
document.body.addEventListener('click', function (e) {
var target = e.target;
if (target.nodeName == 'VIDEO') { // or EMBED
target.style.position = 'absolute';
target.style.width = '100%';
target.style.height = '100%';
}
}, false);
}
});
var video_count = 1;
function runVideo() {
var playDataCounts = $('#playDataCount').val();
if (parseInt(playDataCounts) <= parseInt(video_count)) {
video_count = 1;
} else {
video_count++;
}
var datastring = 'id=' + video_count;
$.ajax({
//ajax function they return time duration of current video or image and play_type_id of next video or image
url: "<?php echo base_url(); ?>video/getScheduleVideoTableDataType",
type: 'POST',
data: datastring,
success: function (msg) {
var fields = msg.split("==");
var play_type_id = fields[0]; //1=video, 2=image
var extention = fields[1];
var duration = fields[2]; //1sec = 1000ms
var muteStatus = fields[3]; //0=mute, 1=unmute
if (play_type_id == 1) {
setTimeout(function () {
$('#player1').show();
$('#LoadDiv').hide();
videoPlayer = document.getElementById("player1");
if (muteStatus == '0') {
videoPlayer.muted = true;
}
var nextVideo = "<?php echo base_url(); ?>images/uploadFile/video" + video_count + ".mp4";
videoPlayer.src = nextVideo;
videoPlayer.play();
videoPlayer.muted = false;
}, duration);
} else if (play_type_id == 2) {
setTimeout(function () {
$('#player1').hide();
$('#LoadDiv').show();
imageShow = document.getElementById("LoadDiv");
if (muteStatus == '0') {
imageShow.muted = true;
}
var nextImage = "<?php echo base_url(); ?>images/uploadFile/video" + video_count + "." + extention;
imageShow.src = nextImage;
runVideo();
}, duration);
}
}
});
}
</script>
---------------------------------------------------------------------------------------------
Call method(function) one controller to onother controller:
---------------------------------------------------------------------------------------------
No comments:
Post a Comment