Tuesday 4 April 2017

How to close tab in JavaScript Event.

<script>
window.onbeforeunload = function () {
    alert("Do you really want to close?");
};
</script>

How to Add Colorpicker in wordpress.

Add function.php 

function jcorgytce_enqueue_color_picker() {
   wp_enqueue_style( 'wp-color-picker' );
   wp_enqueue_script( 'script_handle', plugins_url('your_javascript_file.js', __FILE__ ), array( 'wp-color-picker' ), false, true );
}
add_action( 'admin_enqueue_scripts', 'my_color_picker_function' );


Add JS file :

<script type="text/javascript">
  jQuery(document).ready(function($){
           $('.color-picker').wpColorPicker();
  });
 </script>


<input type="text" class="color-picker" name="overlay_color" value="#EEE" data-default-color="#effeff" />



Thursday 23 February 2017

how to write TEXT on image in php

header ("Content-type: image/jpeg");

$string = "This is simple text";

$font = 20;

$width = imagefontwidth($font) * strlen($string) ;

$height = imagefontheight($font) ;

$im = imagecreatefromjpeg("manjeet.jpg");

$x = imagesx($im) - $width ;

$y = imagesy($im) - $height;

$backgroundColor = imagecolorallocate ($im, 255, 255, 255);

$textColor = imagecolorallocate ($im, 0, 0,0);

imagestring ($im, $font, $x, $y, $string, $textColor);

imagejpeg($im);

Wednesday 15 February 2017

How to save image Bit Code folder and database in android REST API

create new file in php

parameter name : encoding_string

       header('Content-Type: bitmap; charset=utf-8');
        if($_POST['encoding_string']){
        
        $encoding_string=$_POST['encoding_string'];
        
        $image_name=time().'.jpg';
        
        $decode_string = base64_decode($encoding_string);
        
        $path = 'uploads/'.$image_name;
        
        $file= fopen($path,'wb');
        
        $is_written=fwrite($file, $decode_string);
        
        fclose($file);
        
        if($is_written > 0 ){
                                           success here ...........................
                                      }

}
        

Tuesday 10 January 2017

how to get 20 KM area Result in php .

    $distance = (20);  // value is km convent 1 miles = 1.60934 km
    $radius = 6371;
       
        $maxlat =  $latitude + (($distance / $radius) * 180.0 / M_PI);
        $minlat =  $latitude - (($distance / $radius) * 180.0 / M_PI);

        $maxlng = $longitude + (($distance / $radius / cos($latitude * M_PI /180.0))  * 180.0 / M_PI);
        $minlng = $longitude - (($distance / $radius / cos($latitude * M_PI /180.0))  * 180.0 / M_PI);

Use Query--->>

SELECT * FROM table_name WHERE  latitude BETWEEN $minlat AND $maxlat AND longitude BETWEEN $minlng AND $maxlng

Saturday 7 January 2017

Image upload without refresh page in php

index.php


 <html>
<head>
<title>Image upload without refresh page</title>
</head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/3.51/jquery.form.js"></script>
<script type="text/javascript" >
$(document).ready(function() {
$(document).on('change', '#photoimg', function(){
$("#preview").html('');
$("#preview").html('<img src="loader.gif" alt="Uploading...."/>'); //download load loading image
$("#imageform").ajaxForm({
target: '#preview'
}).submit();
});
});
</script>
<style>
body
{
font-family:arial;
}
.preview
{
width:200px;
border:solid 1px #dedede;
padding:10px;
}
#preview
{
color:#cc0000;
font-size:12px
}
</style>
<body>
<div style="width:600px">
<form id="imageform" method="post" enctype="multipart/form-data" action='upload.php'>
Upload your image <input type="file" name="photoimg" id="photoimg" />
<br>
<input type="text" id='tt' name='tt'>
</form>
<div id='preview'>
</div>
</div>
</body>
</html>


upload.php


 <?php
$path = "img/"; // set image upload path
$valid_formats = array(".jpg", ".png", ".gif", ".bmp"); // set formate
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{
//echo $name = $_POST['tt'];//use to image description. and you can do also save in database.
$name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name))
{
$fileExt = substr(strrchr($name, '.'), 0);
if(in_array($fileExt,$valid_formats))
{
if($size<(1024*1024))
{
$actual_image_name = time().$fileExt; // create image unique name
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{
// you can fire query for insert image discription or more fields whoes you create in form.
echo "<img src='img/".$actual_image_name."' class='preview'>";
}
else
echo "failed";
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}

?>

Tuesday 3 January 2017

how to create Your Promo Code in php.

$characters = array(
"A","B","C","D","E","F","G","H","J","K","L","M",
"N","P","Q","R","S","T","U","V","W","X","Y","Z",
"1","2","3","4","5","6","7","8","9");
$keys = array();
while(count($keys) < 8) {
    $x = mt_rand(0, count($characters)-1);
    if(!in_array($x, $keys)) {
       $keys[] = $x;
    }
}
foreach($keys as $key){
   $random_chars .= $characters[$key];
}
echo $random_chars;

Sunday 1 January 2017

how to calculate age time formate function in php

<?php



create function : 




 function get_timeago($ptime)
{
    $estimate_time = time() - $ptime;

    if( $estimate_time < 1 )
    {
        return 'just now';
    }

    $condition = array(
                12 * 30 * 24 * 60 * 60  =>  'year',
                30 * 24 * 60 * 60       =>  'month',
                24 * 60 * 60            =>  'day',
                60 * 60                 =>  'hour',
                60                      =>  'minute',
                1                       =>  'second'
    );

    foreach( $condition as $secs => $str )
    {
        $d = $estimate_time / $secs;
       

        if( $d >= 1 )
        {
            $r = round( $d );
            return 'about ' . $r . ' ' . $str . ( $r > 1 ? 's' : '' ) . ' ago';
        }
    }
}

use function

$timeago = get_timeago(strtotime($datee['date']));

?>

Tuesday 27 December 2016

Load more button data show with ajax in php.

index.php =>

             $rowperpage = 5;
            // counting total number of posts
            $allcount_query = "SELECT count(*) as allcount FROM signup where type='teacher'";
            $allcount_result = mysql_query($allcount_query);
            $allcount_fetch = mysql_fetch_array($allcount_result);
            $allcount = $allcount_fetch['allcount'];

            // select first 5 posts
            $query = "select * from signup where type='teacher' order by id DESC limit 0,$rowperpage ";
            $result = mysql_query($query);

            while($row = mysql_fetch_array($result)){

//your code here...............you want to show .
 
            }
}
            ?>
            <h1 class="load-more button btn">Load More</h1>
            <input type="hidden" id="row" value="0">
            <input type="hidden" id="all" value="<?php echo $allcount; ?>">



.js file =>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

  <script type="text/javascript">
$(document).ready(function(){

    // Load more data
    $('.load-more').click(function(){
        var row = Number($('#row').val());
        var allcount = Number($('#all').val());
        var rowperpage = 5;
        row = row + rowperpage;

        if(row <= allcount){
            $("#row").val(row);

            $.ajax({
                url: 'loadmore.php',
                type: 'post',
                data: {row:row},
                beforeSend:function(){
                    $(".load-more").text("Loading...");
                },
                success: function(response){

                    // Setting little delay while displaying new content
                    setTimeout(function() {
                        // appending posts after last post with class="post"
                        $(".post:last").after(response).show().fadeIn("slow");

                        var rowno = row + rowperpage;

                        // checking row value is greater than allcount or not
                        if(rowno > allcount){

                            // Change the text and background
                            $('.load-more').text("No More Result");
                            $('.load-more').css("background","darkorchid");
                        }else{
                            $(".load-more").text("Load more");
                        }
                    }, 2000);


                }
            });
        }else{
            $('.load-more').text("Loading...");

            // Setting little delay while removing contents
            setTimeout(function() {

                // When row is greater than allcount then remove all class='post' element after 3 element
                $('.post:nth-child(5)').nextAll('.post').remove();

                // Reset the value of row
                $("#row").val(0);

                // Change the text and background
                $('.load-more').text("Load more");
                $('.load-more').css("background","#15a9ce");
             
            }, 2000);


        }

    });

});

  </script>


loadmore.php =>

<?php

//include database configuration file
$row = $_POST['row'];
$rowperpage = 5;

// selecting posts
$query = 'SELECT * FROM signup WHERE type="teacher" order by id DESC limit '.$row.','.$rowperpage;
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){ 

your code here after load more data show.


} ?>



Tuesday 6 December 2016

Page onload automatic click button and link in jquery.

<script>
window.onload = function(){
  document.getElementById("autopop").click();
}
</script>
</head>
<body>
<a href="#" class="link-login" id="autopop"></a>