php下载文件到本机
上一篇 /
下一篇 2011-03-15 14:50:01
/ 个人分类:解决方案
实现最基本的功能:打开页面,点击链接,即下载指定的文件到本机。
down.html
<html>
<head>
<title>download</title>
<meta. http-equiv="Content-Type" content="text/html";charset=gb2312">
</head>
<body>
<a href="down.php">download the file</a>
</body>
</html>
down.php
<?php
// your file to upload
$file = '/home/cuiyao/cyupload/test.txt';
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// tell file size
header('Content-length: '.filesize($file));
// set file name
header('Content-disposition: attachment; filename='.basename($file));
readfile($file);
// Exit script. So that no useless data is output-ed.
exit;
?>
收藏
举报
TAG: