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

文件已存在于以下路径中:

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

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

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

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

Thanks.

推荐答案

您可以使用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相关问答推荐

Livewire 基于下拉 Select 自动填充输入框

在 React 中将属性从一个组件传递到另一个组件

验证判断请求的值是否存在于另一个表 Laravel 9 中

如何使用 laravel 更新单个值

Laravel Eloquent 查找日期超过 2 天的行

Laravel:子文件夹中的 lang 文件

"public/index.php" 可以在 laravel 中按组写入

为什么命令php artisan serve不起作用

Laravel Blade 模板 @foreach 订单

如何修复无效请求(不支持的 SSL 请求)

将 Laravel MYSQL 更改为 utf8mb4 以在现有数据库中支持表情符号

Laravel 5.5 在迁移文件中设置整数字段的大小

Laravel 框架类在 PHPUnit 数据提供程序中不可用

向 Docker 上的 Artisan 推荐方式

如何在 laravel 中解码 Json 对象并在 laravel 中应用 foreach 循环

如何在 Laravel 中正确安装软件包?

Laravel 如何从子域 URL 中删除api前缀

日期时间格式无效:1366 字符串值不正确

Laravel:array_merge():参数#2不是数组错误

Distinct values with pluck