Reputation: 119
I have tried the following method to check if file exist:
@if(file_exists(public_path('/user_img/'.Auth::user()->id.'.jpg')))
It returns false
even when the file exists!
What is wrong with it?
Upvotes: 2
Views: 21674
Reputation: 116
First you have to mention use File at top of the page
$imagepath = "1.jpg";
$directoryPath = 'user_img/'.$imagepath;
if(File::exists($directoryPath)){
//echo "n exist"; die();
} else { echo "not exists"; }
Upvotes: 1
Reputation: 119
I have corrected by adding curly braces to the User id
and it works fine:
@if(file_exists(public_path().'user_img/{{ Auth::User()->id }}.jpg'))
Upvotes: 3