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:

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-14  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 30466
  • 日志数: 22
  • 图片数: 3
  • 建立时间: 2011-03-09
  • 更新时间: 2011-05-17

RSS订阅

Open Toolbar