|
...
|
...
|
@@ -4,9 +4,7 @@ namespace App\Http\Controllers\file; |
|
|
|
|
|
|
|
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;
|
|
...
|
...
|
@@ -43,7 +41,7 @@ class ImageController |
|
|
|
$this->path = $this->config['root'].$this->uploads['path'].'/';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index($hash = '',$type = self::TYPE, $w = 0 ,$h = 0 ){
|
|
|
|
public function index($hash = '', $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;
|
|
...
|
...
|
@@ -54,12 +52,11 @@ 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";
|
|
|
|
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
|
|
|
|
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
|
|
|
|
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 1, $last_modified_time], $this->upload_img['header']);
|
|
|
|
$content = file_get_contents($filename);
|
|
|
|
$header['Content-Length'] = $info['size'];
|
|
|
|
}else{
|
|
...
|
...
|
@@ -70,24 +67,20 @@ class ImageController |
|
|
|
$content = '';
|
|
|
|
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
|
|
|
|
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
|
|
|
|
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
|
|
|
|
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 1, $last_modified_time], $this->upload_img['header']);
|
|
|
|
if ($w > 0 && $h > 0) {
|
|
|
|
$path = $this->cacheImage($info, $w, $h);
|
|
|
|
$content = file_get_contents($path);
|
|
|
|
$header['Content-Length'] = strlen($content);
|
|
|
|
} else {
|
|
|
|
$content = file_get_contents($path);
|
|
|
|
$header['Content-Length'] = $info['size'];
|
|
|
|
$header['Content-Length'] = strlen($content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$header['Content-Type'] = 'image/'.$info['type'];
|
|
|
|
$img_type = $info['type'];
|
|
|
|
$content = base64_encode($content);
|
|
|
|
$img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
|
|
|
|
if($type != self::TYPE){
|
|
|
|
header('Content-Type: image/' . $img_type);
|
|
|
|
echo base64_decode($content);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
return response($img_base64,200,$header);
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|