Wednesday 28 June 2017

how to file delete in s3 bucket in aws in codeniter


how to file delete in s3 bucket in aws in codeigniter


//

Controller


public function seller_kichen_delete(){
       
       
            $replace_image_value = $this->input->post('replace_image_value');
           
            $data = s3_bucket_delete($replace_image_value);
       
    }
   
    // add this code in heleper
    function s3_bucket_delete($temppath){
        $bucket = "bucket-name";
       
        try{
           
           
            $s3Client = new S3Client([
            'version'     => 'latest',
            'region'      => 'us-west-2',
            'credentials' => [
            'key'    => 'key',
            'secret' => 'secret-key',
            ],
            ]);
       
           
                $result = $s3Client->deleteObject([
                'Bucket' => $bucket,
                'Key' => $temppath,
                ]);
                    $data['message'] =  "success";
           
    } catch (Exception $e) {
            $data['message'] =  "false";
            // echo $e->getMessage() . "\n";
            }
           
           
       
        return $data;
       
    }

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