0
我目前正在託管網站文件之前重命名文件。我在用戶下載文件之前重命名文件時遇到問題。當文件上傳時,原始名稱保存在mysql數據庫中,文件被重命名爲一個id。下載PHP
<?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);
}
?>
我希望'$ fileid2','$ filename'和'$ filesize'被存儲到數據庫中,以防止HTTP頭注射之前消毒。 – sarnold
是什麼問題?我沒有看到任何代碼發送文件到客戶端,但否則沒有什麼引人注目的...... – sarnold
您在'header'中使用'$ fileid2'。如果我正確地理解了你,你希望這是一個不同的名字,對嗎? –