<?session_start();
include("../opendb.php");
//print sizeof($a);

if($upd)
{
if($ff !="none")
{
   $fl=$HTTP_POST_FILES['ff']['name'];
   $file_dir=".";
  $tmp_name=$_FILES['ff']['tmp_name'];

   move_uploaded_file($tmp_name,"./txtfiles/$file_dir/$ff_name") or die(' err:could not copy file'.$fl);
  print "File copied :".$fl;
 }
$fp=fopen("./txtfiles/$ff_name","r") or die("Cant open file");
$i=1;
include("opendb.php");
mysqli_query($db,"delete from dailyspare where brcode='$brcode'");
$dt=date("Y-m-d H:i:s");
$i=1;
while(!feof($fp))
{
 $line=fgets($fp,1024);
 $spline=explode("\t",$line);
if(strlen($spline[0])>0)
{
$sql="insert into dailyspare values('".addslashes(trim($spline[0]))."','$spline[1]','$spline[2]', '".$spline[3]."','$brcode','$user','".$dt."')";
//print $i++.". ".$sql."<br>";
mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error());
}
}
print "<script> alert('Done');</script>";
}

?>

<link rel="stylesheet" href="style.css" type="text/css" />
<style>
body,td{font-family:'arial narrow';letter-spacing:1;}
//etr{background-color:c1d799}
.mnu{margin-left:5}
</style>
<center>
<br><br><br><br><br><br>
<form action='<?print $PHP_SELF?>' method='post' ENCTYPE="multipart/form-data">
<table border=0 width=60% cellspacing=1 cellpadding=1 bgcolor='darkbrown'>
<tr><td align=center bgcolor=white>
<table >
<th colspan=2 bgColor=c1d799>Upload Daily Stock
<tr><td>File </td><td><input type=file name='ff'></td></tr>
<tr bgColor='lightsteelblue'><td align=center colspan=2 ><input type=submit value='Upload' name='upd'></td></tr>
</table>
</td></tr>
</table>
</form>
