我有这样的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噢,我的确,可怕的疏忽。 –