Sunday 21 May 2017

Restrict image height and width using J Query.

Restrict image height and width using J Query is very essay. find image upload event using "change" Event. Get image value using "val".

The Below code is very useful to all.

J Query Code
----------------------
$(function() {

var _URL = window.URL || window.webkitURL;

$("#gal_thumb_image").change(function(e) {
    var gal_thumb_image, img;

    if ((gal_thumb_image = this.files[0])) {
        img = new Image();
        img.onload = function() {
if(this.width!==250 || this.height!==250){
alert("Image size should be 250*250");
$('#gal_thumb_image').val('');
return false;
}
alert
        };
        img.onerror = function() {
            alert( "not a valid gal_thumb_image: " + gal_thumb_image.type);
        };
        img.src = _URL.createObjectURL(gal_thumb_image);


    }

});
});

HTML Code
---------------------
<input type="file" id="gal_thumb_image" name="gal_thumb_image"/>

Restrict image size using J Query

Restrict image size very essay. we can find image upload using "change" Event. get value using "val" attribute.

The below code useful  to find Image size

J Query Code
-------------------------
$(function() {
$("#gal_image").change(function(e) {
if(this.files[0].size >= 1073741824){
alert("Image file size should be below 1 GB");
$('#gal_image').val('');
return false;
}

});
});

HTML Code
----------------------

<input type="file" id="gal_image" name="gal_image"  />

Sunday 6 November 2016

Mysql database backup using php and send compresed file to email

Hi Guys it's very easy.

            The below code is used to take completely mysql database backup and then send to email


<?php
$datestamp = date("Y-m-d");      // Current date to append to filename of backup file in format of YYYY-MM-DD

/* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */
$dbuser = "";            // Database username
$dbpwd = "";            // Database password
$dbname = "";            // Database name. Use --all-databases if you have more than one
$filename= "backup-$datestamp.sql.gz";   // The name (and optionally path) of the dump file
$to = "you@remotesite.com";      // Email address to send dump file to
$from = "you@yourhost.com";      // Email address message will show as coming from.
$subject = "MySQL backup file";      // Subject of email

$command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
$result = passthru($command);

$attachmentname = array_pop(explode("/", $filename));   // If a path was included, strip it out for the attachment name

$message = "Compressed database backup file $attachmentname attached.";
$mime_boundary = "< <<:" . md5(time());
$data = chunk_split(base64_encode(implode("", file($filename))));

$headers = "From: $from\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"\r\n";

$content = "This is a multi-part message in MIME format.\r\n\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$content.= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$content.= $message."\r\n";
$content.= "--".$mime_boundary."\r\n";
$content.= "Content-Disposition: attachment;\r\n";
$content.= "Content-Type: Application/Octet-Stream; name=\"$attachmentname\"\r\n";
$content.= "Content-Transfer-Encoding: base64\r\n\r\n";
$content.= $data."\r\n";
$content.= "--" . $mime_boundary . "\r\n";

mail($to, $subject, $content, $headers);

unlink($filename);   //delete the backup file from the server
?>


Tuesday 14 June 2016

how to set password to particular file in the directory

Hi guys it's very simple password protect to particular file in the directory

The below code is used to protect the directory


.htaccess
==========

AuthUserFile /home/ashok/www/api/appchat/report/.htpasswd
AuthType Basic
AuthName "Ashok Only Allowed Valid User"
<Files "userreport.php">
  Require valid-user
</Files>


Here /home/ashok/www/api/appchat/report/ ======> this is file full path
.htpasswd  ======> this is htpassword file

/home/ashok/www/api/appchat/report/.htpasswd  =========> this is htpassword path with file name
userreport.php ====> that particular file name


.htpasswd
=============
together:$apr1$zcGzQRY2$n788sV7DbBEpR2t13bwnS/

together ====>user name (together)
$apr1$zcGzQRY2$n788sV7DbBEpR2t13bwnS/ ======> encrypted password(together)
username:encrypted password


The below path is used to generate .htpasswd username and password

http://www.htaccesstools.com/htpasswd-generator/

Thank you All..

how to set password to directory

Hi guys it's very simple password protect to directory

The below code is used to protect the directory


.htaccess
==========

AuthUserFile /home/ashok/www/api/appchat/report/.htpasswd
AuthType Basic
AuthName "Ashok Only Allowed Valid User"
  Require valid-user


Here /home/ashok/www/api/appchat/report/ ======> this is file full path
.htpasswd  ======> this is htpassword file

/home/ashok/www/api/appchat/report/.htpasswd  =========> this is htpassword path with file name


.htpasswd
=============
together:$apr1$zcGzQRY2$n788sV7DbBEpR2t13bwnS/

together ====>user name (together)
$apr1$zcGzQRY2$n788sV7DbBEpR2t13bwnS/ ======> encrypted password(together)
username:encrypted password


The below path is used to generate .htpasswd username and password

http://www.htaccesstools.com/htpasswd-generator/

Thank you All..

Thursday 3 September 2015

How to track if Email open or not using php?

It is very simple Email open or not using php

We can set one image in hidden field

The image SRC should be go to our website

The mail should be stored in our database

For Example

<img src="www.get2data.com/mailupdate.php?uid=102&mailid=112">

Thursday 14 May 2015

How to get real ip address of a client in case client using proxy server ?

function getRealIPAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}