在我的 laravel 项目中,我已将图像上传到数据库中,并在视图文件中正确显示图像。现在我想获得图像尺寸,那么我该如何获得呢?有人可以帮我吗?这是我上传图片的控制器。
public function store(Request $request)
{
request()->validate([
'image' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
// if ($request->hasFile('image')) {
// $image = $request->file('image');
// $extension = $image->getClientOriginalExtension();
// $filename = time() . "." . $extension;
// $image->move('public/mediaLibrary', $filename);
// }
$image = $request->file('image');
$extension = $image->getClientOriginalExtension();//Getting extension
$originalname = $image->getClientOriginalName();//Getting original name
//this code will store image in laravel default storage folder $path = $image->storeAs('', $originalname);
$path = $image->move('uploads/media/', $originalname);//This will store in customize folder
$imgsizes = $path->getSize();
$mimetype = $image->getClientMimeType();//Get MIME type
//Start Store in Database
$picture = new mediaLibrary();
$picture->mime = $mimetype;
$picture->imgsize = $imgsizes;
$picture->original_filename = $originalname;
$picture->extension = $extension;
$picture->filename = $path;
$picture->save();
//End Store
return redirect()->route('media.index');
}
这是我要显示的刀片文件代码
<div class="card-body" >
<span><i class="fa fa-calendar" aria-hidden="true"></i> Uploaded on:</span>
<strong><p class="text-muted" style="display: inline">
{{ date('F d, Y',strtotime($data->created_at)) }} at {{ date('g : ia',strtotime($data->created_at)) }}
</p></strong>
<hr>
<span>File Name:</span>
<strong><p style="display: inline;">{{$data->original_filename}}</p></strong>
<hr>
<span>File type:</span>
<strong><p style="display: inline;">{{$data->extension}}</p></strong>
<hr>
<span>Fle Size:</span>
<strong><p style="display: inline;"></p>{{round(($data->imgsize)/1024 )}}KB</strong>
{{-- <strong><p style="display: inline;"></p>{{(File::size($data->filename))/1024}} KB</strong> --}}
<hr>
<span>Dimension:</span>
<strong><p style="display: inline;">
</p></strong>
</div>