我想通过向我的 MySQL 服务器发送请求来查找 PHP 的下载时间。我有一张带有用于下载文件的 href 链接的表。如果我单击下载,下载时间应显示在表格中的文件名旁边。
请查看我的代码:
<?php
$con = mysql_connect("localhost","mt","mt");
mysql_select_db("mt", $con);
$d = date("d/m/Y H:i:s");
$result = mysql_query("SELECT * FROM mt_upload");
echo "<table BORDER=2 BORDERCOLOR=RED>
<tr>
<th>FileName</th>
<th>FilePath</th>
<th>Uploaded Date/Time</th><th>Download Date/Time</th>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>
<td>". $row['FileName'] . "</td>
<td ><a href=../sites/default/files/ourfiles/". $row['FileName']." >Download</a></td>
<td>".$row['DateTime']."</td><td>$d</td>
</tr>" ;
}
echo "</table>";
mysql_close($con);
好的,现在我根据OP的评论理解了这个问题。问题是如何确定用户下载文件的时间。如果是这种情况,下载链接需要是一个 php 脚本,它会将时间写入 db,然后将文件的内容返回到具有正确内容标头的流中。
See readfile http://php.net/manual/en/function.readfile.php.
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
您所要做的就是将文件名作为参数传递,并将当前时间写入数据库。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)