日期:2014-05-17  浏览次数:20552 次

PHP header发送各种类型文件及设置文件下载名

<?php

header('Content-type: application/image/pjpeg');//输出的类型
header('Content-Disposition: attachment; filename="downloaded.jpg"'); //下载显示的名字,注意格式
readfile('my.jpg');
// 并将这个文件以前面header发送信息设定的类型输出,从而会弹出一个下载框
// 就是把服务器上的my.jpg下载下来,下载显示和保存的名字默认是downloaded.jpg


?>


各种文件类型的header输出类型如下:
'chm'=>'application/octet-stream',
'ppt'=>'application/vnd.ms-powerpoint',
'xls'=>'application/vnd.ms-excel',
'doc'=>'application/msword',
'exe'=>'application/octet-stream',
'rar'=>'application/octet-stream',
'js'=>"javascrīpt/js",
'css'=>"text/css",
'hqx'=>"application/mac-binhex40",
'bin'=>"application/octet-stream",
'oda'=>"application/oda",
'pdf'=>"application/pdf",
'ai'=>"application/postsrcipt",
'eps'=>"application/postsrcipt",
'es'=>"application/postsrcipt",
'rtf'=>"application/rtf",
'mif'=>"application/x-mif",
'csh'=>"application/x-csh",
'dvi'=>"application/x-dvi",
'hdf'=>"application/x-hdf",
'nc'=>"application/x-netcdf",
'cdf'=>"application/x-netcdf",
'latex'=>"application/x-latex",
'ts'=>"application/x-troll-ts",
'src'=>"application/x-wais-source",
'zip'=>"application/zip",
'bcpio'=>"application/x-bcpio",
'cpio'=>"application/x-cpio",
'gtar'=>"application/x-gtar",
'shar'=>"application/x-shar",
'sv4cpio'=>"application/x-sv4cpio",
'sv4crc'=>"application/x-sv4crc",
'tar'=>"application/x-tar",
'ustar'=>"application/x-ustar",
'man'=>"application/x-troff-man",
'sh'=>"application/x-sh",
'tcl'=>"application/x-tcl",
'tex'=>"application/x-tex",
'texi'=>"application/x-texinfo",
'texinfo'=>"application/x-texinfo",
't'=>"application/x-troff",
'tr'=>"application/x-troff",
'roff'=>"application/x-troff",
'shar'=>"application/x-shar",
'me'=>"application/x-troll-me",
'ts'=>"application/x-troll-ts",
'gif'=>"image/gif",
'jpeg'=>"image/pjpeg",
'jpg'=>"image/pjpeg",
'jpe'=>"image/pjpeg",
'ras'=>"image/x-cmu-raster",
'pbm'=>"image/x-portable-bitmap",
'ppm'=>"image/x-portable-pixmap",
'xbm'=>"image/x-xbitmap",
'xwd'=>"image/x-xwindowdump",
'ief'=>"image/ief",
'tif'=>"image/tiff",
'tiff'=>"image/tiff",
'pnm'=>"image/x-portable-anymap",
'pgm'=>"image/x-portable-graymap",
'rgb'=>"image/x-rgb",
'xpm'=>"image/x-xpixmap",
'txt'=>"text/plain",
'c'=>"text/plain",
'cc'=>"text/plain",
'h'=>"text/plain",
'html'=>"text/html",
'htm'=>"text/html",
'htl'=>"text/html",
'rtx'=>"text/richtext",
'etx'=>"text/x-setext",
'tsv'=>"text/tab-separated-values",
'mpeg'=>"video/mpeg",
'mpg'=>"video/mpeg",
'mpe'=>"video/mpeg",
'avi'=>"video/x-msvideo",
'qt'=>"video/quicktime",
'mov'=>"video/quicktime",
'moov'=>"video/quicktime",
'movie'=>"video/x-sgi-movie",
'au'=>"audio/basic",
'snd'=>"audio/basic",
'wav'=>"audio/x-wav",
'aif'=>"audio/x-aiff",
'aiff'=>"audio/x-aiff",
'aifc'=>"audio/x-aiff",
'swf'=>"application/x-shockwave-flash"
'myz'=>"application/myz"
".*"="application/octet-stream"
".001"="application/x-001"
".301