用户在竞争表单后,我有三个文件被上传到数据库中。问题是我有3个不同的下载脚本来检索文件......这些文件作为{{1}进入数据库}。有没有办法只有1个下载脚本而不是3个不同的脚本?
以下是相关代码:
fileName1, fileName2, fileName3 and File1, File2, File3
我可以将所有$id = $_GET['id'];
$query = "SELECT FileName3, File3 " .
"FROM UserUploads WHERE ID = '$id'";
$result = mysqli_query($connection, $query) or die('Error, query failed');
list($filename3, $file3) = mysqli_fetch_array($result);
header("Content-Disposition: attachment; filename=$filename3");
echo $file3;
添加到fileName1, fileName2, fileName3 and File1, File2, File3
语句中,但问题是SELECT
和header()
之后的行...我怎样才能根据用户点击?
答案 0 :(得分:1)
如果您为一个用户提供3个下载链接。每个链接都有一个参数,例如'file':
http://your-domain.com/download.php?file=1&id=1234
http://your-domain.com/download.php?file=2&id=1234
http://your-domain.com/download.php?file=3&id=1234
将开关案例块添加到您的文件中。
$id = (int)$_GET['id'];
$file = (int)$_GET['file'];
if($file <= 0 || $file >= 4) {
die('bad boy');
}
$query = "SELECT FileName$file as filename, File$file as file " .
"FROM UserUploads WHERE ID = '$id'";
$result = mysqli_query($connection, $query) or die('Error, query failed');
list($fn, $data) = mysqli_fetch_array($result);
header("Content-Disposition: attachment; filename=$fn");
echo $data;
没试过。