从Laravel中的上传文件获取图像扩展名 [英] Get an image extension from an uploaded file in Laravel

查看:812
本文介绍了从Laravel中的上传文件获取图像扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图从上载的文件中获取扩展名,在google上搜索,没有结果.

I have been trying to get the extension from an uploaded file, searching on google, I got no results.

该文件已存在于路径中:

The file already exists in a path:

\Storage::get('/uploads/categories/featured_image.jpg);

现在,如何在上方获取此文件的扩展名?

Now, How can I get the extension of this file above?

使用输入字段,我可以得到如下扩展名:

Using input fields I can get the extension like this:

Input::file('thumb')->getClientOriginalExtension();

谢谢.

推荐答案

您可以使用为此,PHP内置了pathinfo()函数:

$info = pathinfo(storage_path().'/uploads/categories/featured_image.jpg');
$ext = $info['extension'];

或更简洁地说,您可以通过一个选项直接获取它;

Or more concisely, you can pass an option get get it directly;

$ext = pathinfo(storage_path().'/uploads/categories/featured_image.jpg', PATHINFO_EXTENSION);

这篇关于从Laravel中的上传文件获取图像扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆