在files文件类中增加了单个附件信息读取函数,增加了图片附件的mime类型判断函数

This commit is contained in:
Li Jianxuan 2011-11-25 08:55:47 +00:00
parent aa12998965
commit 16ca3d7e5f
1 changed files with 67 additions and 0 deletions

View File

@ -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
/**