本文介紹了確定 Laravel 5 中的文件是否存在的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
目標:如果文件存在,加載文件,否則加載default.png
.
Goal : If the file exist, load the file, else load the default.png
.
我試過了
@if(file_exists(public_path().'/images/photos/account/{{Auth::user()->account_id}}.png'))
<img src="/images/photos/account/{{Auth::user()->account_id}}.png" alt="">
@else
<img src="/images/photos/account/default.png" alt="">
@endif
<小時>
結果
它一直加載我的默認圖像,而我 100% 確定 1002.png
存在.
It kept load my default image while I'm 100% sure that 1002.png
is exist.
如何正確檢查該文件是否存在?
How do I properly check if that file is exist ?
推薦答案
解決方案
@if(file_exists( public_path().'/images/photos/account/'.Auth::user()->account_id.'.png' ))
<img src="/images/photos/account/{{Auth::user()->account_id}}.png" alt="">
@else
<img src="/images/photos/account/default.png" alt="">
@endif
這篇關于確定 Laravel 5 中的文件是否存在的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!