Showing posts with label codeigniter. Show all posts
Showing posts with label codeigniter. Show all posts

Friday 17 April 2020

Create listing with handlebars js with ajax pagination in codeigniter

 Simple Example for Handlebar js with ajax pagination in codeigniter

Create test controller .php




class Test extends MY_Controller
{
function __construct()
{

parent::__construct();
$this->load->model('Test_model');
$this->load->library('pagination');
    $this->load->helper('url'); 
}



public function list()
{
$this->db->select('member_id,first_name,last_name');
$result = $this->db->get('tbl_member', 10, 20);
//echo $this->db->last_query();
$data['data'] = $result->result_array();
echo json_encode($data);

}

public function memberlist()
{
$this->load->view('memberlist');

}

public function loadRecord($rowno=0)
{
   // Row per page
$rowperpage = 5;

    // Row position
if($rowno != 0){
$rowno = ($rowno-1) * $rowperpage;
}

//print_r($rowno);exit;
    // All records count
$allcount = $this->Test_model->getrecordCount();
//print_r([$rowno,$rowperpage]);
    // Get records
$users_record = $this->Test_model->getData($rowno,$rowperpage);
// echo "
";

// print_r($users_record);exit;
//echo $this->db->last_query();exit;
    // Pagination Configuration
$config['base_url'] = base_url().'/test/loadRecord';
$config['use_page_numbers'] = TRUE;
$config['total_rows'] = $allcount;
$config['per_page'] = $rowperpage;

    // Initialize
$this->pagination->initialize($config);

    // Initialize $data Array
$data['pagination'] = $this->pagination->create_links();;
$data['result'] = $users_record;
$data['data'] = $rowno;

echo json_encode($data);
}
}
?>
after create test model .php


class Test_model extends CI_Model
{

public function __construct() {
    parent::__construct(); 
  }

  // Fetch records
  public function getData($rowno,$rowperpage) {
    $this->db->select('*');
    $this->db->from('tbl_member');
    $this->db->limit($rowperpage, $rowno);  
    $query = $this->db->get();
    return $query->result_array();
  }

  // Select total records
  public function getrecordCount() {

    $this->db->select('count(*) as allcount');
    $this->db->from('tbl_member');
    $query = $this->db->get();
    $result = $query->result_array();
    return $result[0]['allcount'];
  }
}

after create view memberlist.php


<html>
<head> <title></title> <script src="https://code.jquery.com/jquery-1.12.4.js" integrity="sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU=" crossorigin="anonymous"></script> </head> <body> <script id="handlebars-demo" type="text/x-handlebars-template"> <table width="100%" style="border: 1px solid;"> <thead> <tr><th style="border: 1px solid;">Memnber id</th> <th style="border: 1px solid;">First Name</th> <th style="border: 1px solid;">Last Name</th></tr> </thead> <tbody> {{#result}} <tr> <td style="border: 1px solid;">{{member_id}}</td> <td style="border: 1px solid;">{{first_name}}</td> <td style="border: 1px solid;">{{last_name}}</td> </tr> {{/result}} </tbody> </table> <div style='margin-top: 10px;' id='pagination'>{{{pagination}}}</div> </script> <div id="test"></div> <script src="https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js"></script> <script > loadPagination(0); function loadPagination(pagno){ $.ajax({ url: "http://graphql.local.com/test/loadRecord/"+pagno, type: 'get', dataType: 'json', success: function(response){ var template = $('#handlebars-demo').html(); var templateScript = Handlebars.compile(template); var html = templateScript(response); //console.log(html); // // Insert the HTML code into the page $("#test").html(html); } }); } $(document).on('click','#pagination a',function(e){ e.preventDefault(); var pageno = $(this).attr('data-ci-pagination-page'); //console.log(pageno); loadPagination(pageno); }); </script> </body> </html>
 




Monday 7 August 2017

Quick image upload using php web service for android and ios

Quick image upload using php web service for android and ios


quick image upload using php web service for android and ios example


<?php



$path="aa/";// Set your path to image upload
if(!is_dir($path)){
mkdir($path);
}
$roomPhotoList = $_POST['image'];
$random_digit=date('Y_m_d_h_i_s');
$filename=$random_digit.'.jpg';
$decoded=base64_decode($roomPhotoList);
file_put_contents($path.$filename,$decoded);

?>

Friday 4 August 2017

Check all with datatables pagination

Check all with datatables pagination

Here example of   Check all with datatables pagination
<body>
<script
  src="http://code.jquery.com/jquery-1.12.4.js"
  integrity="sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU="
  crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css">
<script type="application/javascript" src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<script type="application/javascript">
$(document).ready(function(e) {
   
var oTable = $('#seller_table').DataTable({"bSort":false, responsive: true});

   // var allPages = oTable.cells( ).nodes( ); // Remove comment if you want select all datatable value

    $('body').on("click","#selectAll",function () {
alert();
        if ($(this).hasClass('allChecked')) {
            $('#seller_table').find('input[type="checkbox"]').prop('checked', false);
//$(allPages).find('input[type="checkbox"]').prop('checked', false); // Remove comment if you want select all datatable value
        } else {
            $('#seller_table').find('input[type="checkbox"]').prop('checked', true);
//$(allPages).find('input[type="checkbox"]').prop('checked', true); // Remove comment if you want select all datatable value
        }
        $(this).toggleClass('allChecked');
    })

$("#delete_new_area").click(function(){
var check_all = [];
$(".new_area_value").each(function(index, element) {
           
if(this.checked){
check_all.push($(this).val());
}
        });


if(check_all.length>0){

// here your code for check value;
}
});

$('#seller_table').on('page.dt', function () {

     $('#selectAll').toggleClass('allChecked');
$('#seller_table').find('input[type="checkbox"]').prop('checked', false);
} );

});



</script>
<table id="seller_table" class="table responsive  table-striped table-bordered dataTable no-footer" role="grid" aria-describedby="seller_table_info">
  <thead>
    <tr role="row">
      <th class="sorting_disabled" rowspan="1" colspan="1" style="width: 130px;"> <button type="button" id="selectAll" class="main btn btn-primary "> <span class="sub"></span> Select </button></th>
      <th class="sorting_disabled" rowspan="1" colspan="1" style="width: 280px;">Email</th>
      <th class="sorting_disabled" rowspan="1" colspan="1" style="width: 608px;">Area</th>
    </tr>
  </thead>
  <tbody>
    <tr role="row" class="odd">
      <td><input class="new_area_value" value="4" type="checkbox"></td>
      <td>myinformation@gmail.com</td>
      <td>11416 NE 91ST ST </td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="5" type="checkbox"></td>
      <td>myinformation@gmail.com</td>
      <td>11416 NE 91ST ST </td>
    </tr>
    <tr role="row" class="odd">
      <td><input class="new_area_value" value="6" type="checkbox"></td>
      <td>myinformation@gmail.com</td>
      <td>11416 NE 91ST ST </td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="9" type="checkbox"></td>
      <td>myinformation@gmail.com</td>
      <td>Asheville%2C+NC%2C+United+States</td>
    </tr>
    <tr role="row" class="odd">
      <td><input class="new_area_value" value="10" type="checkbox"></td>
      <td>test@yopmail.com</td>
      <td>Ashburn, VA, United States</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="14" type="checkbox"></td>
      <td>-NA-</td>
      <td>Los Angeles, CA, United States</td>
    </tr>
    <tr role="row" class="odd">
      <td><input class="new_area_value" value="16" type="checkbox"></td>
      <td>-NA-</td>
      <td>Lower Parel, Mumbai, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="17" type="checkbox"></td>
      <td>myinformation@gmail.com</td>
      <td>Lower Parel, Mumbai, Maharashtra, India</td>
    </tr>
    <tr role="row" class="odd">
      <td><input class="new_area_value" value="20" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test Area, Yerawada, Pune, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="21" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test, Janta Road, Dattawadi, Pune, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="21" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test, Janta Road, Dattawadi, Pune, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="21" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test, Janta Road, Dattawadi, Pune, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="21" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test, Janta Road, Dattawadi, Pune, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="21" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test, Janta Road, Dattawadi, Pune, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="21" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test, Janta Road, Dattawadi, Pune, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="21" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test, Janta Road, Dattawadi, Pune, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="21" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test, Janta Road, Dattawadi, Pune, Maharashtra, India</td>
    </tr>
    <tr role="row" class="even">
      <td><input class="new_area_value" value="21" type="checkbox"></td>
      <td>-NA-</td>
      <td>Test, Janta Road, Dattawadi, Pune, Maharashtra, India</td>
    </tr>
  </tbody>
</table>
</body>

Wednesday 28 June 2017

how to image and file upload using aws bucket in codeigniter

how to image and file upload using aws bucket in codeigniter 

public function profile_upload(){


//print_r($_FILES);

if($this->session->userdata('user_login')){


$file = $_FILES['agent_profile_file']['tmp_name'];

    if (file_exists($file))
    {
         $allowedExts = array("gif", "jpeg", "jpg", "png");
$typefile = explode(".", $_FILES["agent_profile_file"]["name"]);
     $extension = end($typefile);

        if (!in_array(strtolower($extension),  $allowedExts))
        {
            //not image
$data['message'] = "images";
        }
        else
        {
$userid =  $this->session->userdata['user_login']['userid'];

$full_path = "agent_image/".$userid."/profileImg/";

/*if(!is_dir($full_path)){
mkdir($full_path, 0777, true);
}*/
$path = $_FILES['agent_profile_file']['tmp_name'];

$image_name = $full_path.preg_replace( "/[^a-z0-9\._]+/", "-", strtolower(uniqid().$_FILES['agent_profile_file']['name']) );
//move_uploaded_file($path,$image_name);



$data['message'] ="sucess";


$s3_bucket = s3_bucket_upload($path,$image_name);


if($s3_bucket['message']=="sucess"){
$data['imagename'] =$s3_bucket['imagepath'];
$data['imagepath'] =$s3_bucket['imagename'];
}

//print_r($imagesizedata);
            //image
            //use $imagesizedata to get extra info
        }
    }
    else
    {
        //not file
$data['message'] = "images";
    }

}else{
$data['message'] = "login";
}
echo json_encode($data);
//$file_name2 = preg_replace("/ /", "-", $file_name);


}
  // Helper file add code 
    // image compress code
function compress($source, $destination, $quality) {

ob_start();
$info = getimagesize($source);

if ($info['mime'] == 'image/jpeg')
$image = imagecreatefromjpeg($source);

elseif ($info['mime'] == 'image/gif')
$image = imagecreatefromgif($source);

elseif ($info['mime'] == 'image/png')
$image = imagecreatefrompng($source);

$filename = tempnam(sys_get_temp_dir(), "beyondbroker");

imagejpeg($image, $filename, $quality);

      //ob_get_contents();
$imagedata =ob_end_clean();
return $filename;
}
   
    // type for if image then it will reduce size
    // site for it in web of mobile because mobile webservice image will in base 64
    // $tempth will file temp path
    // $image_path will file where to save path
   
    function s3_bucket_upload($temppath,$image_path,$type="image",$site="web"){
$bucket = "bucket-name";

$data =array();

$data['message'] =  "false";


// For website only
if($site=="web"){
if($type=="image"){

  $file_Path = compress($temppath,$image_path,90);
 
}else{
  $file_Path =$temppath;
}
}

try{


$s3Client = new S3Client([
'version'     => 'latest',
'region'      => 'us-west-2',
'credentials' => [
'key'    => 'aws-key',
'secret' => 'aws-secretkey',
],
]);

// For website only
if($site=="web"){

$result = $s3Client->putObject([
'Bucket'     => $bucket,
'Key'        => $image_path,
'SourceFile' => $file_Path,
//'body'=> $file_Path,
'ACL'          => 'public-read',
//'StorageClass' => 'REDUCED_REDUNDANCY',
]);

$data['message']  = "sucess";
$data['imagename']  = $image_path;
$data['imagepath']  = $result['ObjectURL'];
}else{

// $tmp = base64_decode($base64);
$upload = $s3Client->upload($bucket, $image_path, $temppath, 'public-read');
$data['message']  = "sucess";
$data['imagepath']  = $upload->get('ObjectURL');


}


} catch (Exception $e) {
$data['message'] =  "false";
// echo $e->getMessage() . "\n";
}



return $data;
}

Stripe checkout.js - passing custom params to token callback

Stripe checkout.js - passing custom params to token callback

<script src="https://checkout.stripe.com/checkout.js"></script>
<button class='pay-deposit' data-booking-id='3455'>Pay Deposit</button>
<button class='pay-deposit' data-booking-id='335'>Pay Deposit</button>
<button class='pay-deposit' data-booking-id='34'>Pay Deposit</button> 
 


 
 # JS file
$('.pay-deposit').on('click', function(event) {
  event.preventDefault();

  // Get booking information from database
  var booking_id = $(this).data('booking-id');
  $.getJSON("/bookings/"+booking_id, function(data) {

    // Open Checkout with further options
    handler = stripe_checkout(booking_id);
    handler.open({
      name: "My Bookings",
      description: data["description"],
      amount: data["amount"],
      email: data["email"],
    });

    // Close Checkout on page navigation
    $(window).on('popstate', function() {
      handler.close();
    });
  });
});

function stripe_checkout(booking_id) {
  var handler = StripeCheckout.configure({
    key: 'pk_test_jPVRpCB1MLjWu2P71eTvXBZD',
    token: function(token) {
      // Send the charge through
      $.post("/charges/create", 
       { token: token.id, booking_id: booking_id }, function(data) {
        if (data["status"] == "ok") {
          window.location = "/some-url";
        } else {
          // Deal with error
          alert(data["message"]);
        }
      });
    }
  });
  return handler;
 }

# Bookings controller
class BookingsController < ApplicationController
  def show
    @booking = Booking.find(params[:id])
    attrs = @booking.attributes
    attrs.merge!("email" => current_user.email)

    respond_to do |format|
      format.json { render json: attrs.to_json }
    end
  end
end

# Charges controller
class ChargesController < ApplicationController

  def create
    booking = Booking.find(params[:booking_id])
    customer = Stripe::Customer.create(card: params[:token])

    charge = Stripe::Charge.create(
      customer:    customer.id,
      amount:      booking.amount,
      description: booking.description,
      currency:    'usd'
     )

    if charge.paid
      # Do some things for successful charge
      respond_to do |format|
        format.json { render json: {status: "ok"}.to_json }
      end
    else
      respond_to do |format|
        format.json { render json: {status: "fail", message: "Error with processing payment.  Please contact support."}.to_json }
      end
    end
  end
end

Wednesday 12 April 2017

create star rating using php

Create star rating example.

Here create fitst stat function and pass the value you want.

and you need font awsome css.

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<?php
function stars($all){
$whole = floor($all);
$fraction = $all - $whole;

if($fraction < .25){
$dec=0;
}elseif($fraction >= .25 && $fraction < .75){
$dec=.50;
}elseif($fraction >= .75){
$dec=1;
}
$r = $whole + $dec;

//As we sometimes round up, we split again
$stars="";
$newwhole = floor($r);
$fraction = $r - $newwhole;
for($s=1;$s<=$newwhole;$s++){
$stars .= "<span class='rating '><i class='fa fa-star' aria-hidden='true'></i></span>";
}
if($fraction==.5){
$stars .= "<span class='rating '><i class='fa fa-star-half-o' aria-hidden='true'></i></span>";
}


if($all!=""||$all!=0){
$gg  = 5-$all;



if($gg>=1 && $gg<2){

$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
}

if($gg>=2 && $gg<3){

$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
}

if($gg>=3  && $gg<4){

$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
}

if($gg>=4 && $gg<5){

$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
}

if($gg==5){

$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
}
}else{

$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";
$stars .= "<span class='rating'><i class='fa fa-star-o' aria-hidden='true'></i></span>";

}
return $stars;
}



echo  stars(0);
echo "<br/>";
echo  stars(1.5);
echo "<br/>";
echo  stars(2);
echo "<br/>";
echo  stars(3);
echo "<br/>";
echo  stars(4);
echo "<br/>";
echo  stars(5);

?>

Thursday 23 February 2017

Pretty Ajax Image Upload Example jquery and php

Hello

Example of image upload using ajax

in we needed  bootstrap.min.css,jquery.form.js,bootstrap.min.js,jquery.form.js,jquery-1.12.4.min.js,jquery-latest.js

first display here php page

pretty.php

<head>


<title>Pretty Ajax Image Upload  Example</title>
<script
              src="https://code.jquery.com/jquery-1.12.4.min.js"
              integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
              crossorigin="anonymous"></script>
              <script src="http://code.jquery.com/jquery-latest.js"/></script>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/3.51/jquery.form.js"></script>
      
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<script type="application/javascript">
$(document).ready(function(e) {
  
    $("#kichen_image_upload_link").click(function() {
        //alert();
        $("#kichen_image_upload_file").trigger('click');
    });

  
function onsuccess(response, status) {

        var result = $.parseJSON(response);
        //alert(result['message']);

        if (result['message'] == "sucess") {
            var imagepath = result['imagename'];
            $("ul.kichen_image_upload li:last").before('<li><a href="#"><img style="height:75px;width:75px;" src="' + imagepath + '" alt="Kitchen"></a></li>');
          
        var images_name =     $('input[name=hidden_kichen_select_image]').val();
      
        if(images_name!=''){
        var get_image = images_name+','+result['imagepath'];
        }else{
            var get_image = result['imagepath'];
        }
        $('input[name=hidden_kichen_select_image]').val(get_image);
      
        } else if (result['message'] == "images") {
            alert('Please select image only');
        } else if (result['message'] == "login") {
            alert('Please login as seller');
        }

        //$("#onsuccessmsg").html("Status :<b>"+status+'</b><br><br>Response Data :<div id="msg" style="border:5px solid #CCC;padding:15px;">'+response+'</div>');
    }

    $("#kichen_image_upload_file").change(function() {
        $("#kichen_image_upload_form").submit();


    });

    $("#kichen_image_upload_form").on('submit', function() {
        var options = {
            url: $(this).attr("action"),
            success: onsuccess
        };
        $(this).ajaxSubmit(options);
        return false;
    });
 });
</script>
<style>
ul li{
    margin:5px;
}
</style>
</head>

<body>

<ul class="kichen_image_upload" style="list-style:none;display:inline-flex;margin:10px;">
                    <li> <a id="kichen_image_upload_link" href="#"> <img src="kitchen5.jpg" alt="image"></a>
                      <form method="POST" action="image_upload.php" id="kichen_image_upload_form">
                        <input style="display:none;" type="file" id="kichen_image_upload_file" name="kichen_image_upload_file"/>
                        <input type="hidden" name="hidden_kichen_select_image"/>
                      </form>
                    </li>
                  </ul>

</body>


after in this ajax request file name is image_upload.php

$file = $_FILES['kichen_image_upload_file']['tmp_name'];
if (file_exists($file))
    {
        $file = $_FILES['kichen_image_upload_file']['tmp_name'];
        $imagesizedata = getimagesize($file);
        if ($imagesizedata === FALSE)
        {
            //not image
            $data['message'] = "images";
        }
        else
        {
       
           
            $full_path = "image/";
           
            if(!is_dir($full_path)){
                mkdir($full_path, 0777, true);
            }
            $path = $_FILES['kichen_image_upload_file']['tmp_name'];
           
            $image_name = $full_path.preg_replace( "/[^a-z0-9\._]+/", "-", strtolower($_FILES['kichen_image_upload_file']['name']) );
            move_uploaded_file($path,$image_name);
           
            $data['message'] ="sucess";
            $data['imagename'] =$image_name;
            $data['imagepath'] =$image_name;
           
            //print_r($imagesizedata);
            //image
            //use $imagesizedata to get extra info
        }
    }
    else
    {
        //not file
        $data['message'] = "images";
    }
    echo json_encode($data);
?>







Sunday 25 December 2016

Get User Media or Image in Your Instagram Example

Hello,


<?php

/* Get image in your instagram Account */

$set_scope_your_app ="https://www.instagram.com/oauth/authorize/?

client_id=Added-your-client_id&

redirect_uri=Added-your-redirect_uri&response_typ

e=code&scope=public_content";


$get_acess_token = "https://instagram.com/oauth/authorize/?

client_id=Added-your-client_id&

redirect_uri=Added-your-redirect_uri&respons

e_type=token";

$url="https://api.instagram.com/v1/users/self/media/recent/?access_token=Added-your-access_token";
 $json = file_get_contents($url);
$data = json_decode($json);


$images = array();
foreach( $data->data as $user_data ) {
    $images[] = (array) $user_data->images;
}

$standard = array_map( function( $item ) {
    return $item['standard_resolution']->url;
}, $images );

echo "<pre>";
print_r($standard);


echo "<pre>";
print_r($standard);

Monday 12 December 2016

remove index.php in codeigniter url in windows and simple server

remove index.php in codeigniter url in windows and simple server

Create .htaccess file


RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]


in windows server create web.config file






   
   

   
   
       
           
           
               
               
           

           
       

   

   



   
   


jquery autocomplete widget example in codeigniter

jquery autocomplete widget example in codeigniter 


// Controller code


public function product_autocomplted(){
$term = $this->input->get('term',true);

$product_autocomplted_q = $this->db->query("SELECT mstproducts.ProductName,mstproducts.ProductID,trnproductimg.Img from mstproducts JOIN trnproductimg on trnproductimg.ProductID = mstproducts.ProductID WHERE mstproducts.ProductName like '%$term%' group by mstproducts.ProductID");
//echo $this->db->last_query();
$i=0;
$data = array();
$count  = $product_autocomplted_q->num_rows();

if($count >0 ){

foreach ($product_autocomplted_q->result_array() as $row){
$data['data'][$i]['lable'] = $row['ProductName'];
$data['data'][$i]['value'] = $row['ProductID'];
$data['data'][$i]['desc'] = $row['Img'];
$i++;

}

}
       
       
        view => html file
         <style>
  .ui-autocomplete-category {
    font-weight: bold;
    padding: .2em .4em;
    margin: .8em 0 .2em;
    line-height: 1.5;
  }
  </style>

  <script>
  jQuery( function() {

var url = "<?php echo base_url(); ?>common/product_autocomplted";


    jQuery( "#search_pp_products,#seach_product_2_pp_products" ).autocomplete({

      source: url,
  //source:project,
      minLength: 2,
      select: function( event, ui ) {


jQuery('body').on("click",".ui-menu-item",function(){



var productid = jQuery(this).find('.ggyy').attr('href');
var productname = jQuery(this).find('.ggyyy').text();
productname = productname.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-')

window.location = "<?php echo base_url(); ?>product-details/"+productname+"/"+productid;

});

return false;

  

      }

    } )

  .data( "ui-autocomplete" )._renderItem = function( ul, item ) {

var html = '';


jQuery.each(item, function(i) {






html =  jQuery( "<li>" )
  .append( "<div class='row'> <div class='col-xs-3'><img id='theImg' src='http://pajjama.in/ProductImg/"+item[i].desc+"'/></div>")
               .append( "<div class='col-xs-9 ggyyy'><a>" + item[i].lable +"</a></div></div><a style='display:none' class='ggyy' href='"+item[i].value+"' ></a>")
               .appendTo( ul );;

 
});
//alert(html)


return html;


             
            }

  } );
  </script>
 
 
  <div class="search-cart ui-widget">



      <input id="search_pp_products" name="q" placeholder="Search" type="text">
     
 

     



      <button type="button" ><i class="fa fa-search"></i></button>



    </div>

Thursday 1 December 2016

login with google with php example

login with google with php example

//login with google with php example

<script
  src="https://code.jquery.com/jquery-1.12.4.min.js"
  integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
  crossorigin="anonymous"></script>
<script src="https://apis.google.com/js/api:client.js"></script>
<script>
var startApp1 = function() {
    gapi.load('auth2', function(){
      // Retrieve the singleton for the GoogleAuth library and set up the client.
      auth2 = gapi.auth2.init({
        client_id: 'your google client id',
        cookiepolicy: 'single_host_origin',
        // Request scopes in addition to 'profile' and 'email'
        //scope: 'additional_scope'
      });
      attachSignin1(document.getElementById('gplus1'));
    });
  };

  function attachSignin1(element) {
    console.log(element.id);
    auth2.attachClickHandler(element, {},
        function(googleUser) {

var facebook_email  = googleUser.getBasicProfile().getEmail();
var facebook_name = googleUser.getBasicProfile().getName();
var get_role_id = 2;
var facebook_login = 0;
  var google_login = 1;

        
               $.ajax({
url:"common/facebook_login",
method:"POST",
data:{facebook_email:facebook_email,facebook_login:facebook_login,google_login:google_login},
success: function(res){
if(jQuery.trim(res)=="Your are successfully login"){
//jQuery('.all_error_here').text(res);
//$("#errorDialog").modal('show');
location.reload();
}else{
jQuery('.all_error_here').text(res);
$("#errorDialog").modal('show');
}

}
});

        }, function(error) {
          alert(JSON.stringify(error, undefined, 2));
        });
  }
  </script>
 

  <script>startApp1();</script>
 
  <button id="gplus1" data-dismiss="modal" data-toggle="modal" class="btn btn-block radius-6 twitter-btn"><i class="fa fa-google-plus"></i> Sign in with Google+</button>

//login with google with php example

login with facebook with php example

login with facebook with php example

//login with facebook with php example
<script
  src="https://code.jquery.com/jquery-1.12.4.min.js"
  integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="
  crossorigin="anonymous"></script>
<script type="application/javascript">

 

  window.fbAsyncInit = function() {
  FB.init({
    appId      : 'your facebook app id',
    cookie     : true,  // enable cookies to allow the server to access
                        // the session
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.8' // use graph api version 2.8
  });

  };
 

  // Load the SDK asynchronously
  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));
 
 
  // Pass function you want to login ur sing up;

  function checkLoginState(login) {
 
 
 

 
 
FB.login(function(response) {
    if (response.authResponse) {
   
  FB.api('/me?fields=id,name,email,permissions', function(response) {
                
var facebook_email  = response.email;
var facebook_name = response.name;
var get_role_id = 2;
var facebook_login = 1;
  var google_login = 0;
if(login == "login"){
  $.ajax({
url:"common/facebook_login",
method:"POST",
data:{facebook_email:facebook_email,facebook_login:facebook_login,google_login:google_login},
success: function(res){
if(jQuery.trim(res)=="Your are successfully login"){
//jQuery('.all_error_here').text(res);
//$("#errorDialog").modal('show');
location.reload();
}else{
jQuery('.all_error_here').text(res);
$("#errorDialog").modal('show');
}
//location.reload();
}
});
}else{
  $.ajax({
url:"common/facebook_signup",
method:"POST",
data:{facebook_email:facebook_email,facebook_name:facebook_name,get_role_id:get_role_id,facebook_login:facebook_login,google_login:google_login},
success: function(res){
/*if(jQuery.trim(res)=="sucess"){
jQuery('.all_error_here').text('Thank you for sign up');
$("#errorDialog").modal('show');
}else{
jQuery('.all_error_here').text(res);
$("#errorDialog").modal('show');
}*/
location.reload();
}
});
}
               });
    } else {
     console.log('User cancelled login or did not fully authorize.');
    }
}, { auth_type: 'reauthenticate' });
 
  }
 
 

</script>

<button data-dismiss="modal" data-toggle="modal" onclick="checkLoginState('login')" class="btn btn-block radius-6 facebook-btn"><i class="fa fa-facebook"></i> Sign in with Facebook</button>


//login with facebook with php example

Tuesday 15 November 2016

php and curl get put post delete example

php and  curl get put post delete example

hello here how to pass value in post and put curl in php. 
see the below example.

/*  PUT CURL EXAMPLE (php and  curl get put post delete example) */

$data = array('email'=>'test@test.com','password'=>'test');
$data_json = json_encode($data);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);


/*  POST CURL EXAMPLE  (php and  curl get put post delete example)*/


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);

/*  GET CURL EXAMPLE  (php and  curl get put post delete example)*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
echo "<pre>";
print_r($response);

/*DELETE CURL EXAMPLE  (php and  curl get put post delete example)*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = curl_exec($ch);
curl_close($ch);
echo "<pre>";
print_r($response);

Saturday 17 September 2016

JQuery Autocomplete example in Codeingniter

JQuery Autocomplete example in Codeingniter

Hello here simple example to autocomplete setup in codegniter

sample code to use it.

 <input type="text"  class="form-control skills"  name="name" placeholder="Type Name"  />
 <style>
.fixedHeight {
   
    font-size:10px;
    max-height: 150px;
    margin-bottom: 10px;
    overflow-x: auto;
    overflow-y: auto;
}


</style>
 <script type="application/javascript">

 $(function() {
$( ".skills" ).autocomplete({
source: '<?php echo base_url() ?>'+'/controler_name/function_name',
   
})
  

$( ".skills" ).autocomplete("widget").addClass("fixedHeight");
});

 </script>

 <?php
 //in controller
 // function name(create you own function name and setup)
 public function userautocompltedservices(){
$term =  $this->input->get('term',true);



$query = $this->db->select('servicename')->from('serviceslist')
       ->where("servicename LIKE '%$term%'")->get();
  
   $datas = $query->result_array();
  foreach($datas as $dat){
 
  $data[] = $dat['servicename'];
}
 
  
   echo json_encode($data);
}

 ?>

 JQuery Autocomplete example in Codeingniter fully example

 

send email using SMTP config in codeigniter 3

Hello

send email using SMTP config in codeigniter 3

here example how to setup SMTP in codeigniter 3

first download the php mailler

put after extract foleder phpmailer folder move to codeigniter in application\libraries

after create libraries in  application\libraries create file my_phpmailer.php

here the code of my_phpmailer.php file

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class My_PHPMailer {
    public function My_PHPMailer() {
        require_once('PHPMailer/PHPMailerAutoload.php');
    }
   
   


}

3) Go To application\helpers create file  sendemails_helper.php

her code of header 


if(!function_exists('send_emails'))
    {
             function send_emails($emails,$body,$subject){
                    $mail = new PHPMailer;
                   
                    $mail->isSMTP();      
                    $mail->Host = 'smtp.mail.yahoo.com';  //                               // Set mailer to use SMTP
                   
                    $mail->SMTPAuth = true;                               // Enable SMTP authentication
                    $mail->Username = 'yahoomail';                 // SMTP username
                    $mail->Password = 'yahoopassword';                           // SMTP password
                    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
                    $mail->Port = 465;                                    // TCP port to connect to
                   
                    $mail->setFrom('jhparmar87@yahoo.com', 'title name');
                   
                   
                    $mail->addAddress($emails, 'user');
               
                   
                    $mail->isHTML(true);                                  // Set email format to HTML
                   
                    $mail->Subject = $subject;
                    $mail->MsgHTML($body);
                   
                    $mail->send();
           
             }
    }

after go to application\config open the file autoload.php

$autoload['libraries'] = array('database','session','My_PHPMailer');// here add you library My_PHPMailer

$autoload['helper'] = array('url', 'file','form','sendemails');// here add you helper file  sendemails

after when controler you want to send mail from smtp setup this helper function

    send_emails("test@yahoo.com","body content","subject"); 

here fully exmple of send email using SMTP config in codeigniter 3 please check it now