慕课网学习笔记
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<a href="1.rar">下载1.rar</a>
<br />
<a href="1.jpg">下载1.jpg</a>
<br />
<a href="doDownload.php?filename=1.jpg">通过程序下载1.jpg</a>
<br />
<a href="doDownload.php?filename=../upload/nv.jpg">下载nv.jpg</a>
</body>
</html>
doDownload.php
<?php
$filename=$_GET['filename'];
header('content-disposition:attachment;filename='.basename($filename));
//attachment 通过附件的方式
//basename()去掉路径,只留下文件名(否则下载到磁盘的文件名会带上路径)
header('content-length:'.filesize($filename));
readfile($filename);
?>