Determine if file exists in a directory or in a path in Laravel

Question:

Determine if file exists in a directory or in a path in Laravel

Solution:


First Look at the Laravel File Exist function Use File at top of the class. Like,
use File;

Then
if(File::exists('full_path'))
{
    echo 'The File is existed in the path';
}

Real Life example of determining if a file is in that folder
if(File::exists('images/students/1200.jpg'))
{
    echo 'Student has an image already';
}


Now see what's in the backend ? Laravel Core function of exists() is -

    /**
     * Determine if a file or directory exists.
     *
     * @param  string  $path
     * @return bool
     */
    public function exists($path)
    {
        return file_exists($path);
    }

So, Laravel exists() function use core PHP's file_exists() function at all.


So, we can now easily determine or get if the file is existed or not. It's a pretty one line function.



Tags:
Determine if file exists in a directory or in a path in Laravel, Laravel if file is esisted in the directory, Laravel check if file is there or not, Laravel check file, Laravel file exist or not, Laravel determine the file,
Determine if file exists in a directory or in a path in Laravel Determine if file exists in a directory or in a path in Laravel Reviewed by Maniruzzaman Akash on October 13, 2017 Rating: 5

No comments:

Powered by Blogger.