0

How to Create Directory if not exists in Laravel

 1 year ago
source link: https://www.laravelcode.com/post/how-to-create-directory-if-not-exists-in-laravel
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Create Directory if not exists in Laravel

  16296 views

  10 months ago

Laravel

In this Article, we will guide you how to create folder in storage in laravel 8 application. we are able to without difficulty create directory if now not exists the use of File or Storage facade in laravel 8 project. i can give you easy and extra solution of laravel 8 make folder in public folder or storage folder.

i'm able to come up with extra way to create folder in public folder in laravel 8. you may see i can use File facade to create folder, Storage facade will use to create directory from storage in laravel 8 and also i'm able to provide you with easy code core php to create folder.

Using File System:

public function createDirecrotory(Request $request)
{
    $path = public_path('upload/laravelcode.com');

    if(!File::isDirectory($path)){
        File::makeDirectory($path, 0777, true, true);
    }

    dd('done');
}

Using Storage System:

public function createFolder()
{
    $response = Storage::makeDirectory('upload/laravelcode.com');
    dd($response);
}

Using Core PHP:

public function removeFolder()
{
    $folderPath = public_path('uploads');
    $response = mkdir($folderPath);
    dd($response);
}
Author : Harsukh Makwana
Harsukh Makwana

Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK