|
...
|
...
|
@@ -6,6 +6,7 @@ use App\Enums\Common\Code; |
|
|
|
use App\Http\Controllers\type;
|
|
|
|
use App\Http\Controllers\统一返回参数;
|
|
|
|
use App\Models\File\Image as ImageModel;
|
|
|
|
use App\Models\User\User as UserModel;
|
|
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
...
|
...
|
@@ -24,6 +25,8 @@ class ImageController |
|
|
|
'Content-Description' => 'File Transfer',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
const TYPE = 1;
|
|
|
|
|
|
|
|
public $path = '';
|
|
|
|
|
|
|
|
public $config = '';
|
|
...
|
...
|
@@ -39,7 +42,7 @@ class ImageController |
|
|
|
$this->path = $this->config['root'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index($hash = '', $w = 0 ,$h = 0){
|
|
|
|
public function index($hash = '',$type = self::TYPE, $w = 0 ,$h = 0 ){
|
|
|
|
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
|
|
|
header("HTTP/1.1 304 Not Modified");
|
|
|
|
exit;
|
|
...
|
...
|
@@ -50,6 +53,7 @@ class ImageController |
|
|
|
$this->response('指定图片不存在!', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
//查看缩略图是否存在
|
|
|
|
// $header['Content-Type'] = 'image/'.$info['type'];
|
|
|
|
$filename = $this->path . $info['hash'] . $w . '_' . $h;
|
|
|
|
if(is_file($filename)){
|
|
|
|
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
|
|
...
|
...
|
@@ -78,7 +82,12 @@ class ImageController |
|
|
|
$img_type = $info['type'];
|
|
|
|
$content = base64_encode($content);
|
|
|
|
$img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
|
|
|
|
return response($img_base64, 200, $header);
|
|
|
|
if($type != self::TYPE){
|
|
|
|
header('Content-Type: image/' . $img_type);
|
|
|
|
echo base64_decode($content);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
return response($img_base64,200,$header);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -114,7 +123,7 @@ class ImageController |
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
|
|
if($image_hash !== false){
|
|
|
|
return $hash;
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
|
|
}
|
|
|
|
$url = $this->path;
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
...
|
...
|
@@ -133,7 +142,7 @@ class ImageController |
|
|
|
if ($rs === false) {
|
|
|
|
return $this->response('添加失败', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
return $hash;
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* 生成缩略图缓存
|
|
...
|
...
|
@@ -186,7 +195,7 @@ class ImageController |
|
|
|
$data[] = $hash;
|
|
|
|
}
|
|
|
|
$imageModel->insert($save_data);
|
|
|
|
return $data;
|
|
|
|
return $this->response('图片资源',Code::SUCCESS,['image'=>$data]);
|
|
|
|
}
|
|
|
|
|
|
|
|
//下载
|
|
...
|
...
|
@@ -206,10 +215,50 @@ class ImageController |
|
|
|
$result = [
|
|
|
|
'msg' => $msg == ' ' ? $code->description : $msg,
|
|
|
|
'code' => $code->value,
|
|
|
|
'data' => $data,
|
|
|
|
'data' => $this->_extents($data),
|
|
|
|
];
|
|
|
|
$this->header['Content-Type'] = $type;
|
|
|
|
$response = response($result,$result_code,$this->header);
|
|
|
|
throw new HttpResponseException($response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $data
|
|
|
|
* @name :返回参数处理
|
|
|
|
* @return array|string
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
protected function _extents($data) {
|
|
|
|
|
|
|
|
if (empty($data) || !is_array($data)) {
|
|
|
|
return empty($data) ? is_array($data) ? [] : '' : $data;
|
|
|
|
}
|
|
|
|
foreach ($data as $k => $v) {
|
|
|
|
if (is_array($v)) {
|
|
|
|
$data[$k] = $this->_extents($v);
|
|
|
|
} else {
|
|
|
|
if (is_null($v)) {
|
|
|
|
$data[$k] = '';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//获取操作人
|
|
|
|
switch ((string) $k) {
|
|
|
|
case 'image':
|
|
|
|
$data['image_link'] = url('/b/image/' . $v);
|
|
|
|
break;
|
|
|
|
case 'images':
|
|
|
|
$v = explode(',',$v);
|
|
|
|
foreach ($v as $k1=>$v1){
|
|
|
|
$data['images_link'][$k1] = url('/b/image/' . $v1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'file':
|
|
|
|
$data['file_link'] = url('/b/file_hash/' . $v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|