php实现文件的下载

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<a href="Download.php?filename=../Angular/1.jpg">下载angular文件夹下面的1.jpg</a>
<a href="Download.php?filename=../CF武器角色大全.zip">下载CF武器角色大全.zip</a>
</body>
</html>

Download.php

<?php
$filename=$_GET['filename'];		//获取文件名	
header('content-disposition:attachment;filename='.$filename);	//告诉浏览器通过何种方式处理文件
header('content-length:'.filesize($filename));	//下载文件的大小
readfile($filename);	 //读取文件
?>

实现效果:

猜你喜欢

转载自blog.csdn.net/qq_42249896/article/details/84584423