【发布时间】:2011-12-06 21:00:59
【问题描述】:
我下载了这段代码用作下载按钮。
<?
$filename = $_GET["filename"];
$buffer = file_get_contents($filename);
/* Force download dialog... */
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
/* Don't allow caching... */
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
/* Set data type, size and filename */
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . strlen($buffer));
header("Content-Disposition: attachment; filename=$filename");
/* Send our file... */
echo $buffer;
?>
问题是,文件名以文件名中的整个路径结尾,例如,这段代码:
<a href="download.php?filename=images/something.jpg">
以名为“images_something.jpg”的图像结束
我想从最终文件名中删除“images_”,到目前为止我还没有运气。
感谢您的帮助!
【问题讨论】:
-
使用该脚本,任何人都可以从您的服务器下载任何文件,所以我会在使用它之前考虑保护它。
-
我不知道,你能给我指一个网站,在那里我可以研究如何保护它吗?