UploadController.php
3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/**
* 图片上传
*
*/
namespace backend\controllers;
use backend\widgets\YHGImage\Upload\Client as UploadClient;
use backend\widgets\YHGImage\Common\Images as CommonImages;
class UploadController extends BaseController
{
/**
* $_FILES test
*/
public function indexAction()
{
$ret = UploadClient::self()->saveImage('image');
$url = CommonImages::getSourceUrl($ret);
$this->renderJson(200,'OK',array(
'uri'=>$ret,
'template'=>CommonImages::getTemplate($ret),
'source'=>CommonImages::getSourceUrl($ret)
));
}
/**
* 图片上传方法
*/
public function actionUploadimg()
{
$images = UploadClient::self()->saveImage('images');
if ($images)
{
$this->renderJson(200, '上传成功', array(
'uri' => $images,
'url' => CommonImages::getSourceUrl($images)
));
}else
{
header('HTTP/1.1 403 Forbidden');
$this->renderJson(403, '上传失败', $images);
}
}
/**
* 身份证照片上传方法
*/
public function uploadidcardAction()
{
$images = UploadClient::self()->uploadIdcard('images');
if ($images)
{
$this->renderJson(200, '上传成功', array(
'uri' => $images,
'url' => CommonImages::getPrivateUrl($images)
));
}else
{
header('HTTP/1.1 403 Forbidden');
$this->renderJson(403, '上传失败');
}
}
/**
* 图片上传 返回值包括base64编码
*/
public function uploadImgReturnFullUrlAction()
{
$images = UploadClient::self()->saveImage('images');
if ($images)
{
$qiniu_url = CommonImages::getImageUrl($images, 100,100);
$file = substr($qiniu_url,0,strrpos($qiniu_url, '?'));
$data = array('src' => $images, 'full_url' => $file);
$this->renderJson(200, '上传成功', $data);
}else
{
header('HTTP/1.1 403 Forbidden');
$this->renderJson(403, '上传失败', array());
}
}
/**
* ckeditor图片上传方法
*/
public function ckeditorImgAction()
{
$param = $this->_getRequests();
$callback = $param['CKEditorFuncNum'];
$images = UploadClient::self()->saveImage('upload');
if ($images)
{
$url = CommonImages::getSourceUrl($images);
exit('<script type="text/javascript">window.parent.parent.CKEDITOR.tools.callFunction('.$callback.', "'.$url.'", "上传成功");</script>');
}else
{
exit('<script type="text/javascript">window.parent.CKEDITOR.tools.callFunction('.$callback.', "", "上传失败");</script>');
}
}
/**
* POST 图片源地址src参数上传,返回绝对路径
*/
public function uploadimgsrcAction()
{
$src = $this->_post('src');
if ($src){
/**
* 读取缓存是否有曾经上传的记录,缓存没有再上传
*/
$redis = CacheManager::Redis();
$key = __FUNCTION__.'#'.$src;
if (!$pic = $redis->get($key)){
if ($pic = UploadClient::self()->uploadStreamImage($src,true)){
$redis->put($key,$pic,1440);
}
}
if ($pic){
$complete_url = CommonImages::getSourceUrl($pic);
$this->renderJson(200, '上传成功', array('url' => $pic,'complete_url'=> $complete_url));
}
}
header('HTTP/1.1 403 Forbidden');
$this->renderJson(403, '上传失败', array());
}
}