Ad

How To Get Extension File In Laravel 5?

- 1 answer

My code in view is like this :

@foreach($news as $row)
    <div class="dealprice">
        <p class="size8 red lh2">File Path: {{ $row->file_path}}</p>
    </div>                  
@endforeach

The result of {{ $row->file_path}} : assets/images/Test.pdf

I want the result : pdf

How do I get the file extension?

Thank you

Ad

Answer

You can use pathinfo:

@foreach($news as $row)
    <div class="dealprice">
        <p class="size8 red lh2">File Path: {{ pathinfo($row->file_path, PATHINFO_EXTENSION)}}</p>
    </div>                  
@endforeach

By passing the second parameter as PATHINFO_EXTENSION it will return only the file extension from the string path.

Ad
source: stackoverflow.com
Ad