码迷,mamicode.com
首页 > Web开发 > 详细

PHP文件下载功能实现

时间:2017-07-19 19:35:42      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:sub   exce   htm   put   header   isp   input   power   file   

直接贴代码!

这是test_download.html,由用户输入文件名,再点击下载,传参给download.php文件

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>测试下载</title>
</head>
<body>
	<form action="download.php" method="post">
		请输入文件名:<input type="text" name="filename">
		<input type="submit" name="submit" value="点击下载">
	</form>
</body>
</html>

 

这是download.php,大部分内容都是header(),差不多包含常用的文件类型了

<?php 
	if($_POST[‘submit‘]){
		$filename=$_POST[‘filename‘];
	}
	header("Content-Type:text/html;charset=utf-8");
	header("Content-Disposition:attachment;filename=".$filename);
	header("Content-Type: image/jpg");
	header("Content-Type:image/png");
	header("Content-Type:image/gif");
	header("Content-Type:image/jpeg");
	header("Content-Type:image/x-png");
	header("Content-Type:text/txt");
	header("Content-Type:text/plain");
	header("Content-Type:text/html");
	header("Content-Type:audio/basic");
	header("Content-Type:audio/x-m4a");
	header("Content-Type:video/mpeg");
	header("Content-Type:application/zip");
	header("Content-Type:application/x-tar");
	header("Content-Type:application/x-gz");
	header("Content-Type:application/msword");
	header("Content-Type:application/powerpoint");
	header("Content-Type:application/vnd.ms-excel");
	header("Content-Type:application/x-msdownload");
	readfile($filename);
 ?>

 

这只是一个示例,至于怎么用,可以自己修改的哈

PHP文件下载功能实现

标签:sub   exce   htm   put   header   isp   input   power   file   

原文地址:http://www.cnblogs.com/-beyond/p/7207285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!