Check If Folder Exists Before Create Directory in Laravel - TechvBlogs

Check If Folder Exists Before Create Directory in Laravel

In this article, You will learn How to Check If Folder Exists Before creating a Directory in Laravel


Suresh Ramani - Author - TechvBlogs
Suresh Ramani
 

2 months ago

Using Laravel's Storage class function exists() you can quickly determine whether a directory is present or not. Additionally, the Storage class has a makeDirectory() function that you can use to create folders and specify their permissions.

Check If Folder Exists Before creating Directory in Laravel

Create a directory with Storage Facades

Syntax

@method static bool makeDirectory(string $path)

Example

use Illuminate\Support\Facades\Storage;
if(!Storage::exists($path)) {
    Storage::makeDirectory($path); //creates directory
}

Create a directory with File Facades

Syntax

@method static bool makeDirectory(string $path, int $mode = 0755, bool $recursive = false, bool $force = false)

Example

use Illuminate\Support\Facades\File;
if(!File::exists($path)) {
    File::makeDirectory($path, 0777, true); //creates directory
}

Thank you for reading this article.

Read Also: How to Create Zip File and Download in Laravel

If you want to manage your VPS / VM Server without touching the command line go and  Checkout this linkServerAvatar allows you to quickly set up WordPress or Custom PHP websites on VPS / VM in a  matter of minutes.  You can host multiple websites on a single VPS / VM, configure SSL certificates, and monitor the health of your server without ever touching the command line interface.

Comments (0)

ServerAvatar
Multiple sites on a single VPS/VM/Server Deploy PHP sites on cloud in minutes, simple as that!
ServerAvatar
Generate Free SSL Certificate - SSLForWeb

Generate Free SSL Certificate

  • 90-Day Certificates
  • SSL Monitoring
  • Wildcard Certificates
  • Multiple Domains
  • Certificate Management
  • Expiration Reminders

Comment


Note: All Input Fields are required.