思路:先指明内容的MIME类型,内容描述,内容长度(也即文件大小)。
一、下载txt文件的程序:
<?php
header(‘Content-Type:text/plain‘);
header(‘Content-Disposition:attachment;filename=y.txt‘);
header(‘Content-Length:‘.filesize(‘y.txt‘));
readfile(‘y.txt‘);
?>
二、下载图片文件程序:
<?php
$filename=‘images/01.gif‘;
header(‘Content-type:image/gif‘);
header(‘content-disposition:attachment;filename=‘.$filename);
header(‘content-length:‘.filesize($filename));
readfile($filename);
?>
三、下载html文件的程序:
<?php
$file=‘r.html‘;
header(‘Content-Type:text/html‘);
header(‘Content-Disposition:attachment;filename=‘.$file);
header(‘Content-Length:‘.filesize($file));
readfile($file);
?>