-1
這是我的代碼。我寫了這個服務的MP3,圖像和視頻。 Mp3文件已收到並運行良好。圖像和視頻已收到但已損壞。我是新來的PHP。PHP - 服務文件出錯
<?php
if(!empty($_GET['type']|| $_GET['name']|| $_GET['ext'])) {
// check if user is logged
if(true) {
$type = preg_replace('#[^-\w]#', '', $_GET['type']);
$name = $_GET['name'] ;
$file = "{$_SERVER['DOCUMENT_ROOT']}/cont/{$type}/{$name}";
echo $file;
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;
}
}
}
die("ERROR: invalid file or you don't have permissions to download it.");
你能幫我嗎?
被警告:現在我可以訪問'http://example.com/download.php?type = null&name = ../../index.php'並下載您的index.php文件,我可以從中推斷代碼其他部分的文件名,直到我下載了整個服務器的內容,可能包括數據庫登錄憑證。 –
定義「損壞」。然後在文本編輯器中打開其中一個文件,檢查是否有任何PHP錯誤消息進入輸出。 – CBroe
請花一些時間閱讀*,更重要的是作爲參考*優秀的網站http://www.phptherightway.com。它將幫助您避免常見的嚴重錯誤和安全隱患 – Martin