<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include("includes/top.php");
include("opendb.php");

 $tbl='spareopstock';

     if(isset($_POST['upd']))
{
    $ff=$_REQUEST['ff'];
  if($ff !="none")
  {
       $imagename=$_FILES['ff']['name'];
       $filepath= "";
       $tmp = $_FILES['ff']['tmp_name'];
       move_uploaded_file($tmp, $filepath . $imagename) or die(' err:could not copy file');
       // print "File copied :".$fl;
   }
     $fp=fopen($filepath.$imagename,"r") or die("Cant open file");
     

  $i=1;
  while(!feof($fp))
  {
    
    $line=fgets($fp,1024);
 $spline=explode("\t",$line);
if(strlen($spline[0])>0)
{
    print $sql="insert into $tbl values('".trim($spline[1])."','".addslashes($spline[2])."','".trim($spline[0])."','".trim($spline[7])."','".trim($spline[3])."','".trim($spline[5])."','".trim($spline[5])."')";
print $i++.". ".$sql."<br>";
mysqli_query($db,$sql) or die('Insert Err:'.mysqli_error($db));
}
else
{
print $spline[0];
}
}
print "<script> alert('Done');</script>";
print "<script> alert('Successfully Uploaded....!!!');</script>";

    $i++; 
  }
  
    

?>
<link rel="stylesheet" href="style.css" type="text/css" />
<style>
body,td{font-family:'calibri';letter-spacing:1;}
tr{background-color:rgb(95, 198, 547);}
.mnu{margin-left:5}
</style>
<center>
<br><br><br><br><br><br>
<form action='' method='post' ENCTYPE="multipart/form-data">
<table border=1 width=60%>
<tr><td> 
<table width=100%>
<th colspan=2><h1>Upload Transfer In</h1>
<tr><td>File <input type=file name='ff'><input type=submit value='Upload' name='upd'></td></tr>
<tr><td>(Convert it to TAB TEXT Format and upload)
 </td></tr>
</table>
</td></tr>
</table>
</form>