PHP开发——隐藏文件下载地址

Home / Article MrLee 2016-3-23 2462

虽然这个技术已经很老了,不过对于我们这些PHP新手来说,还是值得学习下的。特别是重要的文件下载时,如果地址暴露出去,有可能别人能猜测你的结构从而下载你其它文件搞破坏啥的。这个我就不多说了。上代码吧!
	if (file_exists($file)) {
		header('Content-Description: File Transfer');
		header('Content-Type: application/octet-stream');
		header('Content-Disposition: attachment; filename='.basename($file));
		header('Content-Transfer-Encoding: binary');
		header('Expires: 0');
		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
		header('Pragma: public');
		header('Content-Length: ' . filesize($file));
		ob_clean();
		flush();
		readfile($file);
		exit;
	}

$file="file.zip";
可以这么定义,需要在同一级目录下面!

本文链接:https://www.it72.com/8355.htm

推荐阅读
最新回复 (0)
返回