From 16ca3d7e5fb92a61acc0db1dabc9b692082a397e Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 25 Nov 2011 08:55:47 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8files=E6=96=87=E4=BB=B6=E7=B1=BB?= =?UTF-8?q?=E4=B8=AD=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=8D=95=E4=B8=AA=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E4=BF=A1=E6=81=AF=E8=AF=BB=E5=8F=96=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E4=BA=86=E5=9B=BE=E7=89=87=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84mime=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/models/files.php | 67 ++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/application/models/files.php b/application/models/files.php index ee7d3224..99fab011 100644 --- a/application/models/files.php +++ b/application/models/files.php @@ -142,6 +142,73 @@ class files{ } }//文件上传 + /** + * getOne() + * + * 从数据库获取单个文件的信息 + * + * @param int id + * + * return array + */ + static function getOne($db,$id){ + //下载单个附件 + $sql = $db->quoteInto("select a.* from attachments a where a.id=? order by a.ts_created desc",$id); + $att = $db->fetchRow($sql); + if(empty($att['id'])) + { $att['error']=='文件不存在';} + return $att; + } + + + static function getImageType($filename) + { + + //通过mime判断是否是真正的图片 + + $finfo = finfo_open(FILEINFO_MIME_TYPE); + $mime = finfo_file($finfo, $filename); + finfo_close($finfo); + $type = $mime; + if(!in_array($type,array('image/jpeg','image/png'))) + { + return array('error'=>'F'); + }else{ + switch ($type){ + case 'image/jpeg': + $image_create_func = 'imagecreatefromjpeg'; + $image_save_func = 'imagejpeg'; + $new_image_ext='jpg'; + $quality = 100; + break; + case 'image/gif': + $image_create_func = 'imagecreatefromgif'; + $image_save_func = 'imagegif'; + $new_image_ext = 'gif'; + break; + case 'image/png': + $image_create_func = 'imagecreatefrompng'; + $image_save_func = 'imagepng'; + $new_image_ext = 'png'; + $quality = 100; + break; + default: + $image_create_func = 'imagecreatefromjpeg'; + $image_save_func = 'imagejpeg'; + $new_image_ext='jpg'; + $quality = 100; + } + + $downloadcfg = array('creatfunc'=>$image_create_func, + 'savefunc'=>$image_save_func, + 'ext'=>$new_image_ext, + 'mime'=>$mime, + 'quality'=>$quality); + + return $downloadcfg; + } + + }//function getimagetype /**