我目前正在制作一个文件托管网站。在用户下载文件之前重命名文件时遇到问题。上传文件时,原始名称保存在 mysql 数据库中,并将文件重命名为 id。
<?php
require("includes/inc.php");
$id = trim(sanitize($_GET['id'])); //Receives the id of the file from the url
if($id) {
$fileid = mysql_query("SELECT * FROM files WHERE id = '$id'");
if (mysql_num_rows($fileid) != 1) {
header('Location: download.php?error=invalid_file');
exit();
} else {
while($info = mysql_fetch_array($fileid)) {
$fileid2 = $info['id'];
$filename = $info['name'];
$ext = $info['ext'];
$filesize = $info['size'];
$downloads = $info['downloads'];
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Location: uploads/".$fileid2.".".$ext);
header('Content-Disposition: attachment; filename="'.$filename.'"');
header('Content-Length: ' . $filesize);
}
?>