Laravel在刀片中获取文件扩展名

时间:2016-01-03 16:07:39

标签: php laravel blade

如果我想在用户上传docx文件时显示docx图标,则会收到以下错误:

android:focusable="false"
android:focusableInTouchMode="false"

我试着这样:

Call to undefined method Illuminate\Database\Query\Builder::getClientOriginalExtension() (View: /home/vagrant/Code/support/local/resources/views/users/ticket.blade.php)

显然@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 不对。但是我应该使用什么呢?

1 个答案:

答案 0 :(得分:3)

您应该使用:

@if (pathinfo($photo->path, PATHINFO_EXTENSION) == 'docx')

而不是:

@if($photo->getClientOriginalExtension() == 'docx')