Total Pageviews

Monday, November 21, 2011

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.");
}
}

Monday, June 13, 2011

fetch multiple contents with time out using curl with php mutitreading

Follow kvn_krishna on Twitter


this prgm used to fetch  the contents from other servers .... wil set the sleeping time and and will see the time taken and how to fetch ,,, by using curl with php mutitreading
<style type="text/css">
<!--
.style2 {color: #FF0000; font-style:oblique; font-size:24px;}
-->
</style>

<?php
function addHandle(&$curlHandle,$url)
{
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HEADER, 0);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($curlHandle,$cURL);
return $cURL;
}
//execute the handle until the flag passed to function is greater then 0
function ExecHandle(&$curlHandle)
{
$flag=null;
do {
    curl_multi_exec($curlHandle,$flag);//fetch pages in parallel
} while ($flag > 0);
}


$list[1] = "http://www.google.co.in/";
$list[2] = "http://in.yahoo.com/?p=in";
$list[3] = "http://www.rediff.com/";
$list[4] = "http://www.bing.com/";
$curlHandle = curl_multi_init();

for ($i = 1;$i <= 4; $i++)
 $curl[$i] = addHandle($curlHandle,$list[$i]);
ExecHandle($curlHandle);
for ($i = 1;$i <= 4; $i++)
{
// set the sleeping time on 2 seconds
 usleep(2000000);
 {
 // get the content from other servers
 $text[$i] =  curl_multi_getcontent ($curl[$i]);
 echo $text[$i];
  }
 
 echo "<span class='style2'>$i time out".date("h:i:s")."</span>";
}
for ($i = 1;$i <= 4; $i++)//remove the handles
  curl_multi_remove_handle($curlHandle,$curl[$i]);
curl_multi_close($curlHandle);

?>

hit multiple times on the target address using CURL in php multi treading .....

Follow kvn_krishna on Twitter

 this program used to hit the target ftp/http/https........hit  at multiple times... will getta response from multiple times.....i hope  this is example useful for u.... 

example:-

<?php
error_reporting(0);
  // create the multi curl handle
  $mh = curl_multi_init();
  $handles = array();

  for($i=0;$i<5;$i++)
  {
    // create a new single curl handle
    $ch = curl_init();
 
    // setting several options like url, timeout, returntransfer
    // simulate multithreading by calling the wait.php script and sleeping for $rand seconds
    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/IPtest/Timeout.asmx/HelloWorld");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch , CURLOPT_POSTFIELDS,"test='($i+1)'&value='ram'");
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
 
    // add this handle to the multi handle
    curl_multi_add_handle($mh,$ch);
 
    // put the handles in an array to loop this later on
    $handles[] = $ch;
  }

  // execute the multi handle
  $running=null;
  do
  {
    curl_multi_exec($mh,$running);
    // added a usleep for 0.25 seconds to reduce load
    usleep (250000);
  } while ($running > 0);

  // get the content of the urls (if there is any)
  for($i=0;$i<count($handles);$i++)
  {
    // get the content of the handle
    $output=curl_multi_getcontent($handles[$i]);
 
    // remove the handle from the multi handle
    curl_multi_remove_handle($mh,$handles[$i]);
//echo the output to the screen multiple times
echo $output."<br>";

  }

  // echo the output to the screen
// echo $output;

  // close the multi curl handle to free system resources
  curl_multi_close($mh);


?>