zhelon zhelon - 1 year ago 77
PHP Question

How I can know if a folder exists before creating it in laravel?

I need to know if a folder exists before creating it, this is because I store pictures inside and I fear that the pictures are deleted if overwrite the folder.
The code I have to create a folder is as follows

$path = public_path().'/images';
File::makeDirectory($path, $mode = 0777, true, true);

how can I do it?

Answer Source

See: file_exists()


if (!file_exists($path)) {
    // path does not exist

In Laravel:

if(!File::exists($path)) {
    // path does not exist
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download