Skip to main content

Posts

Showing posts with the label php

Fencing ( Latitude Longitude )

 Check Lat/Long is Inside/Outside of fencing <?php function onLine($side,$point)  //check whether p is on the line or not {   if ($point['x'] <= max($side['x']['x'], $side['y']['x']) && $point['x'] <= min($side['x']['x'], $side['y']['x']) &&    ($point['y'] <= max($side['x']['y'], $side['y']['y']) && $point['y'] <= min($side['x']['y'], $side['y']['y'])))       return true; return false; } function direction($point1,$point2,$point3) {    $val=($point2['y']-$point1['y'])*($point3['x']-$point2['x'])-($point2['x']-$point1['x'])*($point3['y']-$point2['y']);    if ($val == 0)    return 0; //colinear    else if ($val <0)    return 2;          //anti-clockwise direction    return 1;          //clockwise direction } function...

WEEK DATE

Previous week - $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); echo $start_week.' '.$end_week ; Current week - $d = strtotime("today"); $start_week = strtotime("last sunday midnight",$d); $end_week = strtotime("next saturday",$d); $start = date("Y-m-d",$start_week); $end = date("Y-m-d",$end_week);  Next Week - $d = strtotime("+1 week -1 day"); $start_week = strtotime("last sunday midnight",$d); $end_week = strtotime("next saturday",$d); $start = date("Y-m-d",$start_week); $end = date("Y-m-d",$end_week);

EMAIL FROM LOCALHOST

<?php         use  PHPMailer\PHPMailer\ PHPMailer ;     use  PHPMailer\PHPMailer\ Exception ;          require   'vendor/autoload.php' ;          $mail  =  new   PHPMailer ( true );          try  {         $mail -> SMTPDebug  =  2 ;                                                $mail -> isSMTP ();                                   ...

Codeigniter initial setup

1. Download Latest version of codeignitor from "https://codeigniter.com/". OR Download from link below : https://drive.google.com/open?id=1K_VZEu2idorUS3vxHiIB5bIzIYt289kH 2. Extract .zip folder and rename it by project name. 3. Place that unziped folder into localhost htdocs folder. 4. Open project in browser as "localhost/projectname", Page with "Welcome to Codeignitor" will appears. 5. Open config.php inside application > config > config.php and set base URL "http://localhost/projectname". 6. Open database.php inside application > config > database.php and set hostname,username,password,database. 7. Create database and tables using localhost/phpmyadmin if not created. 8. Go to application > controller and create new file "Auth.php" as well as go to application > model and create new file Auth_model.php 9. Write this code inside Auth_model.php class Auth_model extends CI_Model { pub...

INSTALL FFMPEG

  https://sites.duke.edu/ddmc/2013/12/30/install-ffmpeg-on-a-mac/ The easiest way to install ffmpeg is to use HomeBrew a package manager for Mac. If you don’t have homebrew installed on your mac already,  run the following command using terminal: `/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ; Once you have Homebrew installed, you can now simply install ffmpeg from terminal with the following command: `brew install ffmpeg`

DELETE MULTIPLE FILES PHP

$path = $_SERVER['DOCUMENT_ROOT'].'/uploads/'; function deleteFiles($path){ $files = glob($path.'*'); // get all file names foreach($files as $file){ // iterate files if(is_file($file)) unlink($file); // delete file  //echo $file.'file deleted'; } }

PHP MAGIC CONSTANTS

PHP has large number of predefined constants. This HOWTO will present the seven most important, most practical and most useful PHP Magic Constants. FILE – The full path and filename of the file. DIR – The directory of the file. FUNCTION – The function name. CLASS – The class name. METHOD – The class method name. LINE – The current line number of the file. NAMESPACE – The name of the current namespace

Video To Thumbnail

Create Thumbnail of video using ffmpeg library. HTML <! DOCTYPE html > < html lang = "en" > < head > < title >Video2Thumbnail</ title > < meta charset = "utf-8" > < meta name = "viewport" content = "width=device-width, initial-scale=1" > < link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css" > < script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js" ></ script > < script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js" ></ script > </ head > < body > < div class = "container" > < div class = "row" > < h1 class = "bg-info" > VIDEO 2 THUMBNAIL </ h1 > < form class = "form-inline" action = "test.php" ...

PHP Generate new pin

New PIN   generate function generatePIN($digits = 4){     $i = 0; //counter      while($i < $digits){         //generate a random number between 0 and 9.         $pin .= mt_rand(0, 9);         $i++;     }     return $pin; } //If I want a 4-digit PIN code. $pin = generatePIN(); 

Widely used Escape Sequences in PHP

\’ – To escape ‘ within single quoted string.     \” – To escape “ within double quoted string.     \\ – To escape the backslash.     \$ – To escape $.     \n – To add line breaks between string.     \t – To add tab space.     \r – For carriage return.

PHP Function to Calculate Hours Difference

function differenceInHours($startdate,$enddate){ $starttimestamp = strtotime($startdate); $endtimestamp = strtotime($enddate); $difference = abs($endtimestamp - $starttimestamp)/3600; return $difference; } if(!empty($_POST["submit"])) { $hours_difference = differenceInHours($_POST["startdate"],$_POST["enddate"]); $message = "The Difference is " . $hours_difference . " hours"; }

PHP , MEMORY, die function, hidestring,

Only variables should be passed by reference $tmp = explode('.', $file_name); $file_extension = end($tmp); ---  public function register_user($user){       $this->db->set($user); $insert =   $this->db->insert('user'); if ($insert){    return $this->db->insert_id(); } else { return false; }      }  public function register_user($user){     $this->db->set($user);   $insert =   $this->db->insert('user'); if ($insert){    return $this->db->insert_id(); } else { return false; }      }  $this->db->set($feild);             $insert = $this->db->insert($tablename);             if ($insert):                 return $this->db->insert_id();             en...