diff --git a/application/models/files.php b/application/models/files.php index c65284b1..0a39cb65 100644 --- a/application/models/files.php +++ b/application/models/files.php @@ -26,6 +26,7 @@ class files{ 'flash' => array('swf', 'flv'), 'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'), 'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2'), + 'reviewatt'=>array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2','gif', 'jpg', 'jpeg', 'png', 'bmp') ); //最大文件大小 $max_size = 1000000; @@ -136,6 +137,73 @@ class files{ }//目录正确性 return $msg; } - } - //文件上传 + }//文件上传 + + + + /** + * downloadFile + * + * 文件下载 + * + * @param String $fullPath e.g. Zend_Registry::get('upload').$fileurl + * + * return file + */ + static function downloadFile( $fullPath ){ + + //判断是否已经输出头部 + if( headers_sent() ) + { + return false; + } + else{ + + // Required for some browsers + @apache_setenv('no-gzip', 1); + @ini_set('zlib.output_compression', 0); + + // File Exists? + if( file_exists($fullPath) ){ + + // Parse Info / Get Extension + $fsize = filesize($fullPath); + $path_parts = pathinfo($fullPath); + $ext = strtolower($path_parts["extension"]); + + // Determine Content Type + switch ($ext) { + case "pdf": $ctype="application/pdf"; break; + case "exe": $ctype="application/octet-stream"; break; + case "zip": $ctype="application/zip"; break; + case "doc": $ctype="application/msword"; break; + case "xls": $ctype="application/vnd.ms-excel"; break; + case "ppt": $ctype="application/vnd.ms-powerpoint"; break; + case "gif": $ctype="image/gif"; break; + case "png": $ctype="image/png"; break; + case "jpeg": + case "jpg": $ctype="image/jpg"; break; + default: $ctype="application/force-download"; + } + + header('Content-Description: File Transfer'); + header("Cache-Control: private",false); + header("Content-Type: $ctype"); + header("Content-Disposition: attachment; filename=\"".basename($fullPath)."\";" ); + header("Content-Transfer-Encoding: binary\n"); + header("Expires: 0"); + header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); + header("Pragma: public"); + header("Content-Length: ".$fsize); + ob_clean(); + flush(); + if(readfile($fullPath)) + return true; + else + return false; + } else + {return false;} + } + } //文件下载 + } \ No newline at end of file