menu
more_vert
PHP文件下载功能实现

作者:dayu


 

这是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文件下载功能实现

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