注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

天上人间*bobo之家

有阳光的时段,就有他(她)的博客文章。也许天气并非晴空万里,博主的“博物钟”却是

 
 
 

日志

 
 

php文件下载类  

2010-01-29 20:28:13|  分类: PHP |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
function file_down($file, $filename = '')
{
        global $PHP_TIME;
        if(!file_exists($file)) showmessage("The file $file is not exists !");
        $filename = $filename ? $filename : basename($file);
        $filetype = fileext($filename);
        $filesize = filesize($file);
    ob_end_clean();
        @set_time_limit(900);
        header('Cache-control: max-age=31536000');
        header('Expires: '.gmdate('D, d M Y H:i:s', $PHP_TIME + 31536000).' GMT');
        header('Content-Encoding: none');
        header('Content-Length: '.$filesize);
        header('Content-Disposition: attachment; filename='.$filename);
        header('Content-Type: '.$filetype);
        readfile($file);
        exit;
}



/**
     * getfiletype
     */
        function get_filetype($fileext){
                $filetype['chm']='application/octet-stream';
                $filetype['ppt']='application/vnd.ms-powerpoint';
                $filetype['xls']='application/vnd.ms-excel';
                $filetype['doc']='application/msword';
                $filetype['exe']='application/octet-stream';
                $filetype['rar']='application/octet-stream';
                $filetype['js']="javascript/js";
                $filetype['css']="text/css";
                $filetype['hqx']="application/mac-binhex40";
                $filetype['bin']="application/octet-stream";
                $filetype['oda']="application/oda";
                $filetype['pdf']="application/pdf";
                $filetype['ai']="application/postsrcipt";
                $filetype['eps']="application/postsrcipt";
                $filetype['es']="application/postsrcipt";
                $filetype['rtf']="application/rtf";
                $filetype['mif']="application/x-mif";
                $filetype['csh']="application/x-csh";
                $filetype['dvi']="application/x-dvi";
                $filetype['hdf']="application/x-hdf";
                $filetype['nc']="application/x-netcdf";
                $filetype['cdf']="application/x-netcdf";
                $filetype['latex']="application/x-latex";
                $filetype['ts']="application/x-troll-ts";
                $filetype['src']="application/x-wais-source";
                $filetype['zip']="application/zip";
                $filetype['bcpio']="application/x-bcpio";
                $filetype['cpio']="application/x-cpio";
                $filetype['gtar']="application/x-gtar";
                $filetype['shar']="application/x-shar";
                $filetype['sv4cpio']="application/x-sv4cpio";
                $filetype['sv4crc']="application/x-sv4crc";
                $filetype['tar']="application/x-tar";
                $filetype['ustar']="application/x-ustar";
                $filetype['man']="application/x-troff-man";
                $filetype['sh']="application/x-sh";
                $filetype['tcl']="application/x-tcl";
                $filetype['tex']="application/x-tex";
                $filetype['texi']="application/x-texinfo";
                $filetype['texinfo']="application/x-texinfo";
                $filetype['t']="application/x-troff";
                $filetype['tr']="application/x-troff";
                $filetype['roff']="application/x-troff";
                $filetype['shar']="application/x-shar";
                $filetype['me']="application/x-troll-me";
                $filetype['ts']="application/x-troll-ts";
                $filetype['gif']="image/gif";
                $filetype['jpeg']="image/pjpeg";
                $filetype['jpg']="image/pjpeg";
                $filetype['jpe']="image/pjpeg";
                $filetype['ras']="image/x-cmu-raster";
                $filetype['pbm']="image/x-portable-bitmap";
                $filetype['ppm']="image/x-portable-pixmap";
                $filetype['xbm']="image/x-xbitmap";
                $filetype['xwd']="image/x-xwindowdump";
                $filetype['ief']="image/ief";
                $filetype['tif']="image/tiff";
                $filetype['tiff']="image/tiff";
                $filetype['pnm']="image/x-portable-anymap";
                $filetype['pgm']="image/x-portable-graymap";
                $filetype['rgb']="image/x-rgb";
                $filetype['xpm']="image/x-xpixmap";
                $filetype['txt']="text/plain";
                $filetype['c']="text/plain";
                $filetype['cc']="text/plain";
                $filetype['h']="text/plain";
                $filetype['html']="text/html";
                $filetype['htm']="text/html";
                $filetype['htl']="text/html";
                $filetype['rtx']="text/richtext";
                $filetype['etx']="text/x-setext";
                $filetype['tsv']="text/tab-separated-values";
                $filetype['mpeg']="video/mpeg";
                $filetype['mpg']="video/mpeg";
                $filetype['mpe']="video/mpeg";
                $filetype['avi']="video/x-msvideo";
                $filetype['qt']="video/quicktime";
                $filetype['mov']="video/quicktime";
                $filetype['moov']="video/quicktime";
                $filetype['movie']="video/x-sgi-movie";
                $filetype['au']="audio/basic";
                $filetype['snd']="audio/basic";
                $filetype['wav']="audio/x-wav";
                $filetype['aif']="audio/x-aiff";
                $filetype['aiff']="audio/x-aiff";
                $filetype['aifc']="audio/x-aiff";
                $filetype['swf']="application/x-shockwave-flash";
                return array_key_exists($fileext, $filetype) ? $filetype[$fileext] : $fileext;
        }
  评论这张
 
阅读(147)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018