我下载了该代码作为下载按钮。下载使用php的图像链接
<?
$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_“,到目前为止我还没有任何运气。
感谢您的帮助!
有了这个脚本,任何人都可以从你的服务器上下载任何文件,所以我会考虑在使用它之前保护它。 – JJJ
我还没有意识到这一点,你能指点我一个网站,我可以研究如何安全吗? –