Laravel - check if folder exists before create directoryBy Hardik Savani | December 13, 2018 | | 9156 Viewer | Category : PHP Laravel
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 "itsolutionstuff.com" on your upload folder in public folder.
public function formSubmit(Request $request)
$path = public_path('upload/itsolutionstuff.com');
File::makeDirectory($path, 0777, true, true);
I hope it can help you...
- PHP Laravel File Upload with Progress Bar Example
- Laravel 5 create word document file using phpoffice/phpword package
- How to clear log file using command in laravel 5 ?
- How to get file size from URL in Laravel 5?
- Laravel 5 create and download zip file example using chumper/zipper composer package
- How to check if file exists or not in Laravel 5?
- PHP: How to count files in folder?
- How to count number of files in folder and remove all files in folder example in Laravel 5 ?