📄 正在查看:twcms/plugin/editor_um/admin_attach_control_after.php
大小:1,422 字节 · 修改:2014-01-08 23:05:38 · 行数:48
1<?php
2
3// 编辑器上传图片
4public function up_image() {
5 $type = R('type');
6 $mid = max(1, (int)R('mid'));
7 $cid = (int)R('cid');
8 $id = (int)R('id');
9 $cfg = $this->runtime->xget();
10
11 if($mid == 1) {
12 // 单页上传的图片量小,所以不保存到数据库。
13 $updir = 'upload/page/';
14 $config = array(
15 'maxSize'=>$cfg['up_img_max_size'],
16 'allowExt'=>$cfg['up_img_ext'],
17 'upDir'=>TWCMS_PATH.$updir,
18 );
19 $up = new upload($config, 'upfile');
20 $info = $up->getFileInfo();
21 }else{
22 // 非单页模型
23 $table = $this->models->get_table($mid);
24 $updir = 'upload/'.$table.'/';
25 $config = array(
26 'maxSize'=>$cfg['up_img_max_size'],
27 'allowExt'=>$cfg['up_img_ext'],
28 'upDir'=>TWCMS_PATH.$updir,
29 );
30 $this->cms_content_attach->table = 'cms_'.$table.'_attach';
31 $info = $this->cms_content_attach->uploads($config, $this->_user['uid'], $cid, $id);
32 }
33 $path = $updir.$info['path'];
34
35 // 是否添加水印
36 if($info['state'] == 'SUCCESS' && !empty($cfg['watermark_pos'])) {
37 image::watermark(TWCMS_PATH.$path, TWCMS_PATH.'static/img/watermark.png', null, $cfg['watermark_pos'], $cfg['watermark_pct']);
38 }
39
40 if($type == 'ajax') {
41 echo '{"path":"'.$path.'","state":"'.$info['state'].'"}';
42 }else{
43 $editorid = preg_replace('/\W/', '', R('editorid'));
44 echo "<script>parent.UM.getEditor('".$editorid."').getWidgetCallback('image')('".$path."','".$info['state']."')</script>";
45 }
46 exit;
47}
48