onlinecode

Laravel – check if folder exists before create directory

Laravel – check if folder exists before create directory

In this post we will give you information about Laravel – check if folder exists before create directory. Hear we will give you detail about Laravel – check if folder exists before create directoryAnd how to use it also give you demo for it if it is necessary.

In this post, i will help to check if directory exists or not before create in laravel 5 application. we can simply check if folder exist when you create new directory using File facade. File facade will provide method to check directory and create directory with permission using isDirectory() and makeDirectory().

we are always looking to create new folder dynamic when you need to store image according to dynamic database records on your project.

isDirectory() will take one argument as folder path and return true if folder exist or false.

makeDirectory() will take four argument for create folder with permission.

I gave you simple controller method example to check if directory exist and create new one if not. Just check bellow example, it will create new folder “onlinecode” on your upload folder in public folder.

Controller Method:

Also see:Laravel 5.7 Import Export Excel to database Example

public function formSubmit(Request $request)

{

$path = public_path('upload/onlinecode');

if(!File::isDirectory($path)){

File::makeDirectory($path, 0777, true, true);

}

dd('done');

}

I hope it can help you…

Hope this code and post will helped you for implement Laravel – check if folder exists before create directory. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Exit mobile version