siiamine's avatar

file management

hello artisan how can i check if a directorie exist ? if not how can i create a new one based on the uploaded file catégorie ? and thanx

0 likes
2 replies
Sergiu17's avatar
if ( is_dir('directory name') ) { echo 'True'; } // if is directory
mkdir('/path/to/my/dir', 0777); // make directory with 777 permissions 
Yorki's avatar

If you are using laravel then you should do it laravel way:

use Illuminate\Support\Facades\File;

...

if (!File::exists($dirPath)) {
    File::makeDirectory($dirPath, 0777, true);
}

// To check if its directory and not file
if (File::isDirectory($dirPath)) {
    ...
}

Please or to participate in this conversation.