File: C:/xampp/htdocs/dpReport/lcdParsing.php
<?php session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Displayer Check</title>
</head>
<body class="oneColElsCtr">
<?php
$sum=260;
$check=1;
$dtime=time();
$dStr=substr($dtime,7,9)."-";
if ($_FILES["file"]["size"] > 0)
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Displayer Checking form! " . "<br />";
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
$filename=$_FILES["file"]["name"];
//echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
// echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/x" .$_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ". "<br />";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" .$_FILES["file"]["name"]);
echo $_FILES["file"]["name"] ." upload sucess! " . "<br />";
echo "Report start: " . "<br />";
// echo "Stored in: " . "upload/" . $_FILES["file"]["name"]. "<br />";
$filename=substr($_FILES["file"]["name"],0,-4);
$computername = "FRED-PC";
$ip = gethostbyname($computername);
echo $ip."<br />";
exec("echo . | icclu -ff -ia -pl -s 255 " ."upload/".$_FILES["file"]["name"]." <Vi24.txt> ".$filename.".txt");
//exec("ping ".$ip." -n 1 -w 90 && exit", $output);
//print_r($output);
///parsing start
$contents = file($filename.".txt");
$string = implode($contents);
//echo $contents[20];
//echo $string;
$p = ereg_replace("\r\n?", "\n", $string);
$p = str_replace("\n", ' ', $p);
//echo $p;
$dot = explode(" ", $p);
//echo $dot[0];
session_start();
$_SESSION["iccpass"]=$filename;
$myFile = "targetlab.txt";
$icclab="upload/".$filename."T.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$fhi = fopen($icclab, 'w') or die("can't open file");
for ( $j = 0; $j <= 23; $j+= 1) {
for ( $i = 7; $i <= 9; $i += 1) {
$stringData = $dot[$i+($j*11)]."\n";
fwrite($fh, $stringData);
fwrite($fhi, $stringData);
}
//fwrite($fh, "\r");
}
fclose($fh);
fclose($fhi);
$connection = mysql_connect("127.0.0.1", "root", "fredsql") or die ("Unable to connect!");
mysql_query("SET NAMES 'utf8'");
$db = "tvicheck-st";
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "INSERT INTO dpReport(company, contact, email, type, filename, score, passbit, date, device, dsn, rankbit) VALUES('$company', '$contact', '$email', '$type', '$filename','$Rsum', '$passbit', NOW(), '$device', '$dsn', '$rankbit')";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
mysql_close($connection);
exec("dispreadAu.exe") ;
}//satrt parsing
}//upload sucess
}//upload check ok
else
{
echo "Invalid file";
}
?>
</table>
<tr>
<br />
<td align="center"><font size="-2"> © <a href="mailto:[email protected]">Fred Kuo</a>, 2010. All rights reserved.<br><a href="http://www.fredkuo.idv.tw/wordpress/?p=1025">Read more.</a><br>
</td>
</tr>
</body>
</html>