Total Pageviews

Tuesday, August 30, 2011

Dissable charactor on text box by javascript ,only allowing numbers at the text box

Follow kvn_krishna on Twitter





Its is used to disabled the charactor key pressing on javascript.
java script function
<--------------------------
 function isnumky(evt)
      {
         var char1 = (evt.which) ? evt.which : event.keycode
         if (char1 > 31 && (char1 < 48 || char1 > 57))
            return false;

         return true;
      }
 ---------------------------------------->
html  form
<input name="textfield" type="text" onkeypress="return isnumky(evnt)" size="50" />






Sunday, August 21, 2011

date of birth to age calculate by using java script regular expresion

Follow kvn_krishna on Twitter
<script type="text/javascript">
function CalculateAge(birthday) {
var re=/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/;
if (birthday.value != '') {
if(re.test(birthday.value ))
{
birthdayDate = new Date(birthday.value);
dateNow = new Date();
var years = dateNow.getFullYear() - birthdayDate.getFullYear();
var months=dateNow.getMonth()-birthdayDate.getMonth();
var days=dateNow.getDate()-birthdayDate.getDate();
if (isNaN(years)) {
document.getElementById('lblAge').innerHTML = '';
document.getElementById('lblError').innerHTML = 'Input date is incorrect!';
return false;
}
else {
document.getElementById('lblError').innerHTML = '';
document.getElementById('lblAge').innerHTML = years +' Years ' +months +' months '+days +' days';
}
}
else
{
document.getElementById('lblError').innerHTML = 'Date must be mm/dd/yyyy format';
return false;
}
}
}
</script>
</head>
<body>
<form id="form1" method="post">
<div>
Date of Birth :<input id="txtAge" onBlur="CalculateAge(this)" />(mm/dd/yyyy)
<span style="color: Red">
<Label ID="lblError" ></Label></span>
<br />
Age&nbsp;&nbsp;&nbsp; : <span id="lblAge"></span>
</div>
</form>

Wednesday, August 10, 2011

water mark in php ..... restrict image file upload

Follow kvn_krishna on Twitter
 

water mark creation with image upload

move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],"userimage/".$_FILES["fileToUpload"]["name"]);
//WaterMarkImages("images/".$_FILES["fileToUpload"]["name"]);
if ((($_FILES["fileToUpload"]["type"] == "image/gif")
|| ($_FILES["fileToUpload"]["type"] == "image/jpeg")
|| ($_FILES["fileToUpload"]["type"] == "image/jpg")
|| ($_FILES["fileToUpload"]["type"] == "image/pjpeg")
|| ($_FILES["fileToUpload"]["type"] == "image/png"))
&& ($_FILES["fileToUpload"]["size"] < 200000))
{
function WaterMarkImages($location)
{
$wm=imagecreatefromgif("image4.gif");
$wm_height=imagesy($wm);
$wm_width=imagesx($wm);
$image=imagecreatetruecolor($wm_width,$wm_height);
$image=imagecreatefromjpeg($location);
$size=getimagesize($location);
$x_pos=$size[0]-$wm-width-90;
$y_pos=$size[1]-$wm-width-800;
imagecopymerge($image,$wm,$x_pos,$y_pos,0,0,$wm_width,$wm_height,100);
imagejpeg($image,$location);
imagedestroy($image);
imagedestroy($wm);
}
call_user_func('WaterMarkImages', "userimage/".$_FILES["fileToUpload"]["name"]);
}
if ((($_FILES["fileToUpload1"]["type"] == "image/gif")
|| ($_FILES["fileToUpload1"]["type"] == "image/jpeg")
|| ($_FILES["fileToUpload1"]["type"] == "image/jpg")
|| ($_FILES["fileToUpload1"]["type"] == "image/pjpeg")
|| ($_FILES["fileToUpload1"]["type"] == "image/png"))
&& ($_FILES["fileToUpload1"]["size"] < 200000))
{
move_uploaded_file($_FILES["fileToUpload1"]["tmp_name"],"jadhagamimage/".$_FILES["fileToUpload1"]["name"]);

//WaterMarkImages1("images1/".$_FILES["fileToUpload1"]["name"]);

function WaterMarkImages1($location)
{
$wm=imagecreatefromgif("image4.gif");
$wm_height=imagesy($wm);
$wm_width=imagesx($wm);
$image=imagecreatetruecolor($wm_width,$wm_height);
$image=imagecreatefromjpeg($location);
$size=getimagesize($location);
$x_pos=$size[0]-$wm-width-90;
$y_pos=$size[1]-$wm-width-800;
imagecopymerge($image,$wm,$x_pos,$y_pos,0,0,$wm_width,$wm_height,100);
imagejpeg($image,$location);
imagedestroy($image);
imagedestroy($wm);
}
call_user_func('WaterMarkImages1', "jadhagamimage/".$_FILES["fileToUpload1"]["name"]);
$sql=("insert into table(fields,image field,,) values ('fields','".$_FILES["fileToUpload"]["name"]."','".$_FILES["fileToUpload1"]["name"]."')");
$n=mysql_query($sql);
header("location:home.");
}
}