Skip to content

Commit

Permalink
fix: 修复图片有旋转参数的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
boxshadow committed May 2, 2018
1 parent 35ca112 commit 841f210
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/Http/Controllers/APIs/V2/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace Zhiyi\Plus\Http\Controllers\APIs\V2;

use Image;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
Expand All @@ -28,6 +29,7 @@
use Zhiyi\Plus\Cdn\UrlManager as CdnUrlManager;
use Zhiyi\Plus\Models\FileWith as FileWithModel;
use Zhiyi\Plus\Models\PaidNode as PaidNodeModel;
use Intervention\Image\Commands\OrientateCommand;
use Illuminate\Contracts\Routing\ResponseFactory as ResponseContract;
use Zhiyi\Plus\Http\Requests\API2\StoreUploadFile as StoreUploadFileRequest;

Expand Down Expand Up @@ -95,13 +97,14 @@ protected function resolveUserPaid($user, PaidNodeModel $node): bool
public function store(StoreUploadFileRequest $request, ResponseContract $response, Carbon $dateTime, FileModel $fileModel, FileWithModel $fileWith)
{
$fileModel = $this->validateFileInDatabase($fileModel, $file = $request->file('file'), function (UploadedFile $file, string $md5) use ($fileModel, $dateTime): FileModel {
// 图片做旋转处理
Image::make($file->getRealPath())->orientate()->save($file->getRealPath(), 100);

list($width, $height) = ($imageInfo = @getimagesize($file->getRealPath())) === false ? [null, null] : $imageInfo;
$path = $dateTime->format('Y/m/d/Hi');

if (($filename = $file->store($path, config('cdn.generators.filesystem.disk'))) === false) {
abort(500, '上传失败');
return $response->json(['message' => '上传失败'], 500);
}

$fileModel->filename = $filename;
$fileModel->hash = $md5;
$fileModel->origin_filename = $file->getClientOriginalName();
Expand All @@ -112,7 +115,6 @@ public function store(StoreUploadFileRequest $request, ResponseContract $respons

return $fileModel;
});

$fileWith = $this->resolveFileWith($fileWith, $request->user(), $fileModel);

return $response->json([
Expand Down

0 comments on commit 841f210

Please sign in to comment.