|
@@ -6,6 +6,7 @@ use App\Enums\Common\Code; |
|
@@ -6,6 +6,7 @@ use App\Enums\Common\Code; |
|
6
|
use App\Http\Controllers\type;
|
6
|
use App\Http\Controllers\type;
|
|
7
|
use App\Http\Controllers\统一返回参数;
|
7
|
use App\Http\Controllers\统一返回参数;
|
|
8
|
use App\Models\File\Image as ImageModel;
|
8
|
use App\Models\File\Image as ImageModel;
|
|
|
|
9
|
+use App\Models\User\User as UserModel;
|
|
9
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
10
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
10
|
use Illuminate\Http\JsonResponse;
|
11
|
use Illuminate\Http\JsonResponse;
|
|
11
|
use Illuminate\Support\Facades\Storage;
|
12
|
use Illuminate\Support\Facades\Storage;
|
|
@@ -24,6 +25,8 @@ class ImageController |
|
@@ -24,6 +25,8 @@ class ImageController |
|
24
|
'Content-Description' => 'File Transfer',
|
25
|
'Content-Description' => 'File Transfer',
|
|
25
|
],
|
26
|
],
|
|
26
|
];
|
27
|
];
|
|
|
|
28
|
+ const TYPE = 1;
|
|
|
|
29
|
+
|
|
27
|
public $path = '';
|
30
|
public $path = '';
|
|
28
|
|
31
|
|
|
29
|
public $config = '';
|
32
|
public $config = '';
|
|
@@ -39,7 +42,7 @@ class ImageController |
|
@@ -39,7 +42,7 @@ class ImageController |
|
39
|
$this->path = $this->config['root'];
|
42
|
$this->path = $this->config['root'];
|
|
40
|
}
|
43
|
}
|
|
41
|
|
44
|
|
|
42
|
- public function index($hash = '', $w = 0 ,$h = 0){
|
45
|
+ public function index($hash = '',$type = self::TYPE, $w = 0 ,$h = 0 ){
|
|
43
|
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
46
|
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
|
44
|
header("HTTP/1.1 304 Not Modified");
|
47
|
header("HTTP/1.1 304 Not Modified");
|
|
45
|
exit;
|
48
|
exit;
|
|
@@ -50,6 +53,7 @@ class ImageController |
|
@@ -50,6 +53,7 @@ class ImageController |
|
50
|
$this->response('指定图片不存在!', Code::USER_ERROR);
|
53
|
$this->response('指定图片不存在!', Code::USER_ERROR);
|
|
51
|
}
|
54
|
}
|
|
52
|
//查看缩略图是否存在
|
55
|
//查看缩略图是否存在
|
|
|
|
56
|
+// $header['Content-Type'] = 'image/'.$info['type'];
|
|
53
|
$filename = $this->path . $info['hash'] . $w . '_' . $h;
|
57
|
$filename = $this->path . $info['hash'] . $w . '_' . $h;
|
|
54
|
if(is_file($filename)){
|
58
|
if(is_file($filename)){
|
|
55
|
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
|
59
|
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
|
|
@@ -78,7 +82,12 @@ class ImageController |
|
@@ -78,7 +82,12 @@ class ImageController |
|
78
|
$img_type = $info['type'];
|
82
|
$img_type = $info['type'];
|
|
79
|
$content = base64_encode($content);
|
83
|
$content = base64_encode($content);
|
|
80
|
$img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
|
84
|
$img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
|
|
81
|
- return response($img_base64, 200, $header);
|
85
|
+ if($type != self::TYPE){
|
|
|
|
86
|
+ header('Content-Type: image/' . $img_type);
|
|
|
|
87
|
+ echo base64_decode($content);
|
|
|
|
88
|
+ exit;
|
|
|
|
89
|
+ }
|
|
|
|
90
|
+ return response($img_base64,200,$header);
|
|
82
|
}
|
91
|
}
|
|
83
|
|
92
|
|
|
84
|
/**
|
93
|
/**
|
|
@@ -114,7 +123,7 @@ class ImageController |
|
@@ -114,7 +123,7 @@ class ImageController |
|
114
|
$imageModel = new ImageModel();
|
123
|
$imageModel = new ImageModel();
|
|
115
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
124
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
116
|
if($image_hash !== false){
|
125
|
if($image_hash !== false){
|
|
117
|
- return $hash;
|
126
|
+ return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
118
|
}
|
127
|
}
|
|
119
|
$url = $this->path;
|
128
|
$url = $this->path;
|
|
120
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
129
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
@@ -133,7 +142,7 @@ class ImageController |
|
@@ -133,7 +142,7 @@ class ImageController |
|
133
|
if ($rs === false) {
|
142
|
if ($rs === false) {
|
|
134
|
return $this->response('添加失败', Code::USER_ERROR);
|
143
|
return $this->response('添加失败', Code::USER_ERROR);
|
|
135
|
}
|
144
|
}
|
|
136
|
- return $hash;
|
145
|
+ return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
137
|
}
|
146
|
}
|
|
138
|
/**
|
147
|
/**
|
|
139
|
* 生成缩略图缓存
|
148
|
* 生成缩略图缓存
|
|
@@ -186,7 +195,7 @@ class ImageController |
|
@@ -186,7 +195,7 @@ class ImageController |
|
186
|
$data[] = $hash;
|
195
|
$data[] = $hash;
|
|
187
|
}
|
196
|
}
|
|
188
|
$imageModel->insert($save_data);
|
197
|
$imageModel->insert($save_data);
|
|
189
|
- return $data;
|
198
|
+ return $this->response('图片资源',Code::SUCCESS,['image'=>$data]);
|
|
190
|
}
|
199
|
}
|
|
191
|
|
200
|
|
|
192
|
//下载
|
201
|
//下载
|
|
@@ -206,10 +215,50 @@ class ImageController |
|
@@ -206,10 +215,50 @@ class ImageController |
|
206
|
$result = [
|
215
|
$result = [
|
|
207
|
'msg' => $msg == ' ' ? $code->description : $msg,
|
216
|
'msg' => $msg == ' ' ? $code->description : $msg,
|
|
208
|
'code' => $code->value,
|
217
|
'code' => $code->value,
|
|
209
|
- 'data' => $data,
|
218
|
+ 'data' => $this->_extents($data),
|
|
210
|
];
|
219
|
];
|
|
211
|
$this->header['Content-Type'] = $type;
|
220
|
$this->header['Content-Type'] = $type;
|
|
212
|
$response = response($result,$result_code,$this->header);
|
221
|
$response = response($result,$result_code,$this->header);
|
|
213
|
throw new HttpResponseException($response);
|
222
|
throw new HttpResponseException($response);
|
|
214
|
}
|
223
|
}
|
|
|
|
224
|
+
|
|
|
|
225
|
+ /**
|
|
|
|
226
|
+ * @param $data
|
|
|
|
227
|
+ * @name :返回参数处理
|
|
|
|
228
|
+ * @return array|string
|
|
|
|
229
|
+ * @author :liyuhang
|
|
|
|
230
|
+ * @method
|
|
|
|
231
|
+ */
|
|
|
|
232
|
+ protected function _extents($data) {
|
|
|
|
233
|
+
|
|
|
|
234
|
+ if (empty($data) || !is_array($data)) {
|
|
|
|
235
|
+ return empty($data) ? is_array($data) ? [] : '' : $data;
|
|
|
|
236
|
+ }
|
|
|
|
237
|
+ foreach ($data as $k => $v) {
|
|
|
|
238
|
+ if (is_array($v)) {
|
|
|
|
239
|
+ $data[$k] = $this->_extents($v);
|
|
|
|
240
|
+ } else {
|
|
|
|
241
|
+ if (is_null($v)) {
|
|
|
|
242
|
+ $data[$k] = '';
|
|
|
|
243
|
+ continue;
|
|
|
|
244
|
+ }
|
|
|
|
245
|
+ //获取操作人
|
|
|
|
246
|
+ switch ((string) $k) {
|
|
|
|
247
|
+ case 'image':
|
|
|
|
248
|
+ $data['image_link'] = url('/b/image/' . $v);
|
|
|
|
249
|
+ break;
|
|
|
|
250
|
+ case 'images':
|
|
|
|
251
|
+ $v = explode(',',$v);
|
|
|
|
252
|
+ foreach ($v as $k1=>$v1){
|
|
|
|
253
|
+ $data['images_link'][$k1] = url('/b/image/' . $v1);
|
|
|
|
254
|
+ }
|
|
|
|
255
|
+ break;
|
|
|
|
256
|
+ case 'file':
|
|
|
|
257
|
+ $data['file_link'] = url('/b/file_hash/' . $v);
|
|
|
|
258
|
+ break;
|
|
|
|
259
|
+ }
|
|
|
|
260
|
+ }
|
|
|
|
261
|
+ }
|
|
|
|
262
|
+ return $data;
|
|
|
|
263
|
+ }
|
|
215
|
} |
264
|
} |