增加了元数据评审附件上传后图片类型附件生成预览的功能
This commit is contained in:
parent
ad8deb86ea
commit
8b3da22dfb
|
@ -610,14 +610,22 @@ class ServiceController extends Zend_Controller_Action
|
||||||
$filedesc = $this->_request->getParam('filedesc');
|
$filedesc = $this->_request->getParam('filedesc');
|
||||||
$filetype = $this->_request->getParam('dir');
|
$filetype = $this->_request->getParam('dir');
|
||||||
$realname = $msg['realname'];
|
$realname = $msg['realname'];
|
||||||
|
$fileurl = $msg['file_url'];
|
||||||
|
|
||||||
$sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','reviewatt','$filedesc','$userid','$filesize','$realname') RETURNING id";
|
$sql = "insert into attachments (filename,filetype,filedesc,userid,filesize,realname) values ('$filename','reviewatt','$filedesc','$userid','$filesize','$realname') RETURNING id";
|
||||||
$sth = $this->db->prepare($sql);
|
$sth = $this->db->prepare($sql);
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
$att = $sth->fetch(PDO::FETCH_ASSOC);
|
$att = $sth->fetch(PDO::FETCH_ASSOC);
|
||||||
$msg['attid'] = $attid = $att['id'];
|
$msg['attid'] = $attid = $att['id'];
|
||||||
$msg['html'] = $realname.'[已完成]<input type="hidden" name="atts[]" value="'.$attid.'" /><div class="cancel"><a href="javascript:;" id="deletebtn_'.$attid.'"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>';
|
|
||||||
|
include_once('files.php');
|
||||||
|
$imgct = files::getImageType($this->config->upload.$filename);
|
||||||
|
|
||||||
|
if(!isset($imgct['error'])) $preview = '<img src="/service/attpreview/id/'.$attid.'" style="display:block;" />';
|
||||||
|
else $preview = "";
|
||||||
|
|
||||||
|
$msg['html'] = $preview.$realname.'[已完成]<input type="hidden" name="atts[]" value="'.$attid.'" /><div class="cancel"><a href="javascript:;" id="deletebtn_'.$attid.'"><img border="0" src="/static/js/uploadify/cancel.png" /></a></div>';
|
||||||
|
$msg['preview'] = "/service/attpreview/id/".$attid;
|
||||||
echo Zend_Json::encode($msg);
|
echo Zend_Json::encode($msg);
|
||||||
exit();
|
exit();
|
||||||
}else{
|
}else{
|
||||||
|
@ -740,6 +748,60 @@ class ServiceController extends Zend_Controller_Action
|
||||||
{
|
{
|
||||||
throw new Exception('发生严重意外!您确认链接正确?');
|
throw new Exception('发生严重意外!您确认链接正确?');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function attpreviewAction(){
|
||||||
|
|
||||||
|
$this->_helper->layout->disableLayout();
|
||||||
|
$this->_helper->viewRenderer->setNoRender();
|
||||||
|
|
||||||
|
$id=(int)$this->_request->getParam('id');
|
||||||
|
|
||||||
|
include_once('files.php');
|
||||||
|
$info = files::getOne($this->db,$id);
|
||||||
|
|
||||||
|
if(!empty($info['error']))
|
||||||
|
{
|
||||||
|
exit($info['error']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try{
|
||||||
|
$filename = $this->config->upload.$info['filename'];
|
||||||
|
$imgct = files::getImageType($filename);
|
||||||
|
if(isset($imgct['error'])) exit("Error");
|
||||||
|
//var_dump($imgct);exit();
|
||||||
|
$src = $imgct['creatfunc']($filename);
|
||||||
|
|
||||||
|
list($width_orig, $height_orig) = getimagesize($filename);
|
||||||
|
|
||||||
|
if($width_orig>300)
|
||||||
|
{
|
||||||
|
$width = 300;
|
||||||
|
$ratio = $width_orig/300;
|
||||||
|
$height = $height_orig/$ratio;
|
||||||
|
}else{
|
||||||
|
$width = $width_orig;
|
||||||
|
$height = $height_orig;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置图片尺寸
|
||||||
|
$image_p = imagecreatetruecolor($width, $height);
|
||||||
|
$white = imagecolorallocate($image_p, 255, 255, 255);
|
||||||
|
imagefilledrectangle($image_p, 0, 0, $width, $height, $white);
|
||||||
|
|
||||||
|
imagecopyresampled($image_p, $src, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
|
||||||
|
|
||||||
|
header("Content-type: image/jpeg");
|
||||||
|
imagejpeg($image_p);
|
||||||
|
imagedestroy($src);
|
||||||
|
imagedestroy($image_p);
|
||||||
|
|
||||||
|
exit;
|
||||||
|
}catch(Exception $e){
|
||||||
|
echo $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue