From 9cf3dbb7f4e438233ba522ded579e903a8ac4942 Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Sun, 12 Sep 2010 08:23:12 +0000 Subject: [PATCH] * rewrite the download logic. --- module/file/control.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/module/file/control.php b/module/file/control.php index 05743f2546..d162f45811 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -35,22 +35,21 @@ class file extends control public function download($fileID, $mouse = '') { $file = $this->file->getById($fileID); - $fileTypes = array('txt', 'jpg', 'jpeg', 'gif', 'png', 'bmp', 'xml', 'html'); - foreach($fileTypes as $fileType) - { - if($file->extension == $fileType) - { - $download = 'false'; - break; - } - } - if(isset($download) && $mouse == 'left') + + /* 判断是下载还是打开。*/ + $mode = 'down'; + $fileTypes = 'txt|jpg|jpeg|gif|png|bmp|xml|html'; + if(strpos($fileTypes, $file->extension) !== false and $mouse == 'left') $mode = 'open'; + + /* 模式为open,直接在浏览器打开。*/ + if($mode == 'open') { if(file_exists($file->realPath))$this->locate($file->webPath); $this->app->error("The file you visit $fileID not found.", __FILE__, __LINE__, true); } else { + /* 下载文件。*/ if(file_exists($file->realPath)) { $fileName = $file->title . '.' . $file->extension;