これはこれまで私が試したことです。ボタン1をクリックするとsome.txtがダウンロードされます。ボタン2をクリックすると、blue.txtをダウンロードするのと同じことが起こります。もうsome.txtを取得します。ユーザーがボタン2をクリックしたときのテーブルでは、blue.txtファイルのみをダウンロードできるはずです。あなたはファイルことをダウンロードするためのリンクや別のスクリプトを置く必要異なるIDを持つボタンをクリックすると、別のファイルをダウンロードするときに同じファイルがダウンロードされます
<?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=='') {
\t $id = $_SESSION["id"];
\t $time = Now();
\t $insert = $con->query("INSERT INTO my_table (LoggedIn) Values($time) WHERE id = '$id'");
}
else{
\t $id = $_SESSION["id"];
\t $update = $con->query("UPDATE my_table SET LoggedIn = Now() WHERE id = '$id'");
}
\t 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 -->
\t <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>
\t <!--<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">
\t \t \t <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>
\t <br/>
\t <br/>
\t <br/>
\t <br/>
\t <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">
\t <thead>
\t <tr>
\t <th style="text-align:center;">FileID</th>
\t \t <th style="text-align:center;">FileName</th>
\t \t <th style="text-align:center;">Download File</th>
\t </tr>
\t </thead>
\t <tbody>
<?php
$res = $con->query("select * from File_Table");
while ($row = $res->fetch_assoc()) {
?>
\t <tr>
\t <td><?php echo $row['FileID']; ?></td>
\t \t <td><?php echo $row['FileName']; ?></td>
\t \t <td>
\t \t <form action="user.php" method="post">
\t \t <input type="submit" name="Download" id="<?php echo $row['FileID'];?>" value="<?php echo $row['FileID'];?>">
<?php
\t \t $file_row = $row['FileID']; echo $file_row; $file_name = $row['FileName']; echo $file_name;
\t \t if(isset($_POST['Download'])){
\t
\t $results = $con->query("select * from File_Table where FileID = '$file_row'");
if($rows = $results->fetch_assoc()){
\t $uploading = $rows['FileName'];
\t echo $uploading;
\t $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;
}
}
}
?>
\t \t </form>
\t \t </td>
\t </tr>
<?php
}
?>
\t </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>
追記:これは(今= '$時間をあなたに失敗します);'。あなたは未定義の一定の通知を得るでしょう。 –
ヘッドアップのおかげで –