This is what I tried so far,when I click on button 1 it downloads some.txt. When I click on button 2 the same thing happens instead of downloading blue.txt i get some.txt again. In my table when the user clicks on button 2 they should be able to download the blue.txt file only.
<?php
error_reporting(E_ALL & ~E_NOTICE);
include 'connection/connection.php';
session_start();
if(isset($_SESSION["id"])) {
$username = $_SESSION['username'];
$result = $con->query("select * from my_table where UserName='$username'");
$row = $result->fetch_assoc();
$log = $row['LoggedIn'];
if($log=='') {
$id = $_SESSION["id"];
$time = Now();
$insert = $con->query("INSERT INTO my_table (LoggedIn) Values($time) WHERE id = '$id'");
}
else{
$id = $_SESSION["id"];
$update = $con->query("UPDATE my_table SET LoggedIn = Now() WHERE id = '$id'");
}
if(isset($_POST['LogOut'])){
header('Location:LogOut.php');
}
}
/* need to add this later
else{
header('Location: LogIn.php');
exit;
} */
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>User Api Docs</title>
<!-- Bootstrap -->
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!--<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">API Docs User</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="LogOut.php" style="text-decoration:none;">Log Out</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<br/>
<br/>
<br/>
<br/>
<div class="text-center">
Welcome! <?php echo $row['UserName']; ?>. You are logged in. Your UserID is <?php echo $row['id'];?>
<br/>
<br/>
<div class="container">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th style="text-align:center;">FileID</th>
<th style="text-align:center;">FileName</th>
<th style="text-align:center;">Download File</th>
</tr>
</thead>
<tbody>
<?php
$res = $con->query("select * from File_Table");
while ($row = $res->fetch_assoc()) {
?>
<tr>
<td><?php echo $row['FileID']; ?></td>
<td><?php echo $row['FileName']; ?></td>
<td>
<form action="user.php" method="post">
<input type="submit" name="Download" id="<?php echo $row['FileID'];?>" value="<?php echo $row['FileID'];?>">
<?php
$file_row = $row['FileID']; echo $file_row; $file_name = $row['FileName']; echo $file_name;
if(isset($_POST['Download'])){
$results = $con->query("select * from File_Table where FileID = '$file_row'");
if($rows = $results->fetch_assoc()){
$uploading = $rows['FileName'];
echo $uploading;
$file = 'docs_uploaded/'. $uploading;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
}
}
?>
</form>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
<!-- jQuery (necessary for Bootstrap's Javascript plugins) -->
<script type="text/javascript" src="js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script type="text/javascript" src="bootstrap/js/bootstrap.js"></script>
</body>
</html>
</div>