. filesize ( $new_file ) ); //告诉浏览器,文件大小 @readfile ( $new_file );//输出文件;

2、封装成方法

function down_file($url,$type='application/zip'){
    header("Cache-Control: public"); 
    header("Content-Description: File Transfer"); 
    header('Content-disposition: attachment; filename='.basename($url)); //文件名 
    header("Content-Type: ".$type); //zip格式的 
    header("Content-Transfer-Encoding: binary"); //告诉浏览器,这是二进制文件 
    header('Content-Length: '. filesize($url)); //告诉浏览器,文件大小 
    @readfile($url);
}

3、”Cache-Control: XXX”解析

请求头javascript

max-age
  客户端不肯意接受age超过这个值的缓存。而且不接受过时缓存,除非max-stale存在。 老是有值css

max-stale
  若是有值,客户端能够接受过时时间不超过指定值的缓存
  若是没有值,客户端愿意接受过时缓存而不管过时太久。html

min-fresh
  客户端愿意接受一个新鲜度不小于当前age加上指定时间的响应。简单说在指定的后续一段时间内不会过时的响应。 老是有值java

no-cache
  客户端示意缓存,在使用缓存的时候必须进行校验。 。没有值web

no-store
  客户端示意缓存,不要存储本次请求的响应。可是对于已经缓存的内容则没有影响。 浏览器

no-transform
  不得对资源进行转换或转变。缓存

only-if-cached
  客户端只接受缓存给出的响应,若是缓存没有命中应该返回一个504 服务器

响应头
must-revalidate
  一旦缓存过时,必须向源服务器进行校验,不得使用过时内容。若是没法链接必须返回504。
没有值cookie

no-cache
  若是值,在没有成功经过源站校验的状况下不得使用缓存。 有值,在进行验证的时候不要发送值指示的头域。 如Cache-Control: no-cache=”set-cookie,set-cookie2”,表示不要携带cookie进行验证。 关于带有值的状况介绍较少,这里有一个讨论:no-cache头带值时app

no-store
  不要缓存当前请求的响应 。没有值

no-transform
  与请求头语义相同

public
  任何缓存均可以进行缓存,即便响应默认是不可缓存或仅私有缓存可存的状况。

private
  没有值,公有缓存不可存储;即便默认是不可缓存的,私有缓存也能够存储 。有值,将无值时的做用,限制到指定头字段上。公有有缓存不可存储指定的头字段,而其余字段能够缓存。

proxy-revalidate
  与must-revalidate相同,但仅对公共缓存生效。 没有值

max-age
  在通过指定时间后将过时 。有值

s-maxage
  指定响应在公共缓存中的最大存活时间,它覆盖max-age和expires字段。

4、Content-Type:application/xxx解析

‘ez’ => ‘application/andrew-inset’,

‘hqx’ => ‘application/mac-binhex40’,

‘cpt’ => ‘application/mac-compactpro’,

‘doc’ => ‘application/msword’,

‘bin’ => ‘application/octet-stream’,

‘dms’ => ‘application/octet-stream’,

‘lha’ => ‘application/octet-stream’,

‘lzh’ => ‘application/octet-stream’,

‘exe’ => ‘application/octet-stream’,

‘class’ => ‘application/octet-stream’,

‘so’ => ‘application/octet-stream’,

‘dll’ => ‘application/octet-stream’,

‘oda’ => ‘application/oda’,

‘pdf’ => ‘application/pdf’,

‘ai’ => ‘application/postscript’,

‘eps’ => ‘application/postscript’,

‘ps’ => ‘application/postscript’,

‘smi’ => ‘application/smil’,

‘smil’ => ‘application/smil’,

‘mif’ => ‘application/vnd.mif’,

‘xls’ => ‘application/vnd.ms-excel’,

‘ppt’ => ‘application/vnd.ms-powerpoint’,

‘wbxml’ => ‘application/vnd.wap.wbxml’,

‘wmlc’ => ‘application/vnd.wap.wmlc’,

‘wmlsc’ => ‘application/vnd.wap.wmlscriptc’,

‘bcpio’ => ‘application/x-bcpio’,

‘vcd’ => ‘application/x-cdlink’,

‘pgn’ => ‘application/x-chess-pgn’,

‘cpio’ => ‘application/x-cpio’,

‘csh’ => ‘application/x-csh’,

‘dcr’ => ‘application/x-director’,

‘dir’ => ‘application/x-director’,

‘dxr’ => ‘application/x-director’,

‘dvi’ => ‘application/x-dvi’,

‘spl’ => ‘application/x-futuresplash’,

‘gtar’ => ‘application/x-gtar’,

‘hdf’ => ‘application/x-hdf’,

‘js’ => ‘application/x-javascript’,

‘skp’ => ‘application/x-koan’,

‘skd’ => ‘application/x-koan’,

‘skt’ => ‘application/x-koan’,

‘skm’ => ‘application/x-koan’,

‘latex’ => ‘application/x-latex’,

‘nc’ => ‘application/x-netcdf’,

‘cdf’ => ‘application/x-netcdf’,

‘sh’ => ‘application/x-sh’,

‘shar’ => ‘application/x-shar’,

‘swf’ => ‘application/x-shockwave-flash’,

‘sit’ => ‘application/x-stuffit’,

‘sv4cpio’ => ‘application/x-sv4cpio’,

‘sv4crc’ => ‘application/x-sv4crc’,

‘tar’ => ‘application/x-tar’,

‘tcl’ => ‘application/x-tcl’,

‘tex’ => ‘application/x-tex’,

‘texinfo’ => ‘application/x-texinfo’,

‘texi’ => ‘application/x-texinfo’,

‘t’ => ‘application/x-troff’,

‘tr’ => ‘application/x-troff’,

‘roff’ => ‘application/x-troff’,

‘man’ => ‘application/x-troff-man’,

‘me’ => ‘application/x-troff-me’,

‘ms’ => ‘application/x-troff-ms’,

‘ustar’ => ‘application/x-ustar’,

‘src’ => ‘application/x-wais-source’,

‘xhtml’ => ‘application/xhtml+xml’,

‘xht’ => ‘application/xhtml+xml’,

‘zip’ => ‘application/zip’,

‘au’ => ‘audio/basic’,

‘snd’ => ‘audio/basic’,

‘mid’ => ‘audio/midi’,

‘midi’ => ‘audio/midi’,

‘kar’ => ‘audio/midi’,

‘mpga’ => ‘audio/mpeg’,

‘mp2’ => ‘audio/mpeg’,

‘mp3’ => ‘audio/mpeg’,

‘aif’ => ‘audio/x-aiff’,

‘aiff’ => ‘audio/x-aiff’,

‘aifc’ => ‘audio/x-aiff’,

‘m3u’ => ‘audio/x-mpegurl’,

‘ram’ => ‘audio/x-pn-realaudio’,

‘rm’ => ‘audio/x-pn-realaudio’,

‘rpm’ => ‘audio/x-pn-realaudio-plugin’,

‘ra’ => ‘audio/x-realaudio’,

‘wav’ => ‘audio/x-wav’,

‘pdb’ => ‘chemical/x-pdb’,

‘xyz’ => ‘chemical/x-xyz’,

‘bmp’ => ‘image/bmp’,

‘gif’ => ‘image/gif’,

‘ief’ => ‘image/ief’,

‘jpeg’ => ‘image/jpeg’,

‘jpg’ => ‘image/jpeg’,

‘jpe’ => ‘image/jpeg’,

‘png’ => ‘image/png’,

‘tiff’ => ‘image/tiff’,

‘tif’ => ‘image/tiff’,

‘djvu’ => ‘image/vnd.djvu’,

‘djv’ => ‘image/vnd.djvu’,

‘wbmp’ => ‘image/vnd.wap.wbmp’,

‘ras’ => ‘image/x-cmu-raster’,

‘pnm’ => ‘image/x-portable-anymap’,

‘pbm’ => ‘image/x-portable-bitmap’,

‘pgm’ => ‘image/x-portable-graymap’,

‘ppm’ => ‘image/x-portable-pixmap’,

‘rgb’ => ‘image/x-rgb’,

‘xbm’ => ‘image/x-xbitmap’,

‘xpm’ => ‘image/x-xpixmap’,

‘xwd’ => ‘image/x-xwindowdump’,

‘igs’ => ‘model/iges’,

‘iges’ => ‘model/iges’,

‘msh’ => ‘model/mesh’,

‘mesh’ => ‘model/mesh’,

‘silo’ => ‘model/mesh’,

‘wrl’ => ‘model/vrml’,

‘vrml’ => ‘model/vrml’,

‘css’ => ‘text/css’,

‘html’ => ‘text/html’,

‘htm’ => ‘text/html’,

‘asc’ => ‘text/plain’,

‘txt’ => ‘text/plain’,

‘rtx’ => ‘text/richtext’,

‘rtf’ => ‘text/rtf’,

‘sgml’ => ‘text/sgml’,

‘sgm’ => ‘text/sgml’,

‘tsv’ => ‘text/tab-separated-values’,

‘wml’ => ‘text/vnd.wap.wml’,

‘wmls’ => ‘text/vnd.wap.wmlscript’,

‘etx’ => ‘text/x-setext’,

‘xsl’ => ‘text/xml’,

‘xml’ => ‘text/xml’,

‘mpeg’ => ‘video/mpeg’,

‘mpg’ => ‘video/mpeg’,

‘mpe’ => ‘video/mpeg’,

‘qt’ => ‘video/quicktime’,

‘mov’ => ‘video/quicktime’,

‘mxu’ => ‘video/vnd.mpegurl’,

‘avi’ => ‘video/x-msvideo’,

‘movie’ => ‘video/x-sgi-movie’,

‘ice’ => ‘x-conference/x-cooltalk’,