Note: Please refer my previous post for inserting an image into MYSQL Database. http://www.marskarthik.com/blog/?p=652

$sql = “select * from `mytable`.`picture` LIMIT 1″;
$result = mysql_query($sql) or die(‘Bad query!’.mysql_error());
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
$db_img = $row['IMAGE'];
}
$db_img = base64_decode($db_img); //print_r($db_img );
$db_img = imagecreatefromstring($db_img);
if ($db_img !== false) {
imagegif($db_img);
}
imagedestroy($db_img);

You need to first create a table with the mysql code as shown below

CREATE TABLE `mytable`.`mypicture` (
`ID` INT( 5 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`IMAGE` BLOB NOT NULL
) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;

First you will have code for connecting to mysql with username and password. Then here comes the php code for inserting image.

$handle = fopen(“mylogo.gif”, “rb”);
$img = fread($handle, filesize(‘mylogo.gif’));
fclose($handle);
$img = base64_encode($img);
$sql = “INSERT INTO `mytable`.`picture`(`IMAGE`) VALUES (‘$img’)”;
mysql_query($sql) or die(‘Bad Query’);
echo “Success!!!!”;

Note: Below code is used to find the Workgroup of a windows system on your network provided your web server runs on a windows machine. This code use windows “nbtstat” command to get this information.

< ?php

function ip2wgroup($ip)
{
$out = trim(shell_exec(“nbtstat -A $ip”));
$str1=”<20> UNIQUE Registered”;
$str2=”<1E> GROUP Registered”;
$str3=”<00> GROUP Registered”;
$x1=strpos($out,$str1);
$x2=strpos($out,$str2);
$x3=strpos($out,$str3);
if(($x2-$x1)< =50)
{
$len=strlen($str1);
$value=substr($out,$x1+$len,$x2-($x1+$len));
$value=trim($value);
}
else
{
$len=strlen($str1);
$value=substr($out,$x1+$len,$x3-($x1+$len));
$value=trim($value);
}
return($value);
}

echo ip2wgroup(“192.168.1.100″);
?>

Note: Below code is used to find the Hostname/Computername of a windows system on your network provided your web server runs on a windows machine. This code use windows “nbtstat” command to get this information.

< ?php

function ip2host($ip)
{
$out = trim(shell_exec(“nbtstat -A $ip”));
$str1=”———————————————”;
$str2=”<00> UNIQUE Registered”;
$x1=strpos($out,$str1);
$x2=strpos($out,$str2);
$len=strlen($str1);
$value=substr($out,$x1+$len,$x2-($x1+$len));
$value=trim($value);
return($value);
}

echo ip2host(“192.168.1.100″);

?>

Note: Below code is used to find the MAC address of a windows system on your network provided your web server runs on a windows machine. This code use windows “nbtstat” command to get this information.


< ?php

function ip2mac($ip)
{
$out = trim(shell_exec(“nbtstat -A $ip”));
$length=strlen($out);
$mac=”";
for ($i=17; $i>=1; $i–)
{
$mac= $mac . $out[$length-$i];
}
return($mac);
}

echo ip2mac(“192.168.1.100″);

?>


< ?php
function randpass()
{
$len=6;// Set the length of password
$passwd = “”;
$mypasschar = “1b2c3d45f6g7h89j!k@#m^n

q[r]s{t}(v)wxyz”;//List of possible password characters
$temp = 0;
while ($temp < $len)
{
$char = substr($mypasschar, mt_rand(0, strlen($mypasschar)-1), 1);
if (!strstr($passwd, $char)) //Finding duplicate character
{
$passwd .= $char;
$temp++;
}
}
return $passwd;
}

echo randpass();

?>