我有這樣的PHP代碼:如何在本PHP代碼中防止本地文件下載?
<?php
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".$_GET['name']."\"");
$file_content = file_get_contents($_GET['name']);
echo $file_content;
?>
在這種情況下,攻擊者可以申請在我的網站上下載文件:
localhost/file.php?name=../../../../../../../etc/passwd
我需要一種方法來防止用戶下載任何東西從當前目錄中除去.zip
文件。
如果(!strpos($ _ GET [ '名'], '..')==假)退出; –
@IgorPantović這是不夠的,只是開始使用絕對路徑名稱 –
@MichaelHelwig噢,我的確,可怕的疏忽。 –