Laravel 在刀片中获取文件扩展名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34578577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:57:40 来源:igfitidea点击:
Laravel get file extension in blade
提问by Jamie
When I want to show a docx icon if a user has uploaded a docx file I receive the following error:
如果用户上传了 docx 文件,我想显示 docx 图标时,我收到以下错误:
Call to undefined method Illuminate\Database\Query\Builder::getClientOriginalExtension() (View: /home/vagrant/Code/support/local/resources/views/users/ticket.blade.php)
I'm trying it like this:
我正在尝试这样:
@foreach($ticket->image as $photo)
@if($photo->getClientOriginalExtension() == 'docx')
<img src="icons/word.png">
@else
<a href="{{ $photo->path }}"><img src="{{ $photo->path }}" alt=""/></a>
@endif
@endforeach
Obviously the getClientOriginalExtension()
is not right. But what should I use instead?
显然getClientOriginalExtension()
是不对的。但是我应该用什么来代替?
回答by Marcin Nabia?ek
You should use:
你应该使用:
@if (pathinfo($photo->path, PATHINFO_EXTENSION) == 'docx')
instead of:
代替:
@if($photo->getClientOriginalExtension() == 'docx')