mr-abdellah's avatar

Laravel Can't Access Network Drive for File Storage

Hi everyone,

I'm trying to configure Laravel to store uploaded files on a network drive, but I'm running into issues. I hope someone here can help!

My Setup Laravel version: 10.x

OS: Windows Server 2019

Web server: IIS

Network share: \CORP-SERVER\SharedDocs\laravel_uploads

Mapped drive: X:\ (mapped to the above network share)

What I Want I want Laravel to save uploaded files to a folder on the network drive, for example: X:\project_files\invoices\

What I Tried I mapped the network share to X: using:

text net use X: \CORP-SERVER\SharedDocs\laravel_uploads /persistent:yes In config/filesystems.php:

php 'disks' => [ 'local' => [ 'driver' => 'local', 'root' => 'X:\project_files\invoices', ], ], My upload code uses:

php $path = $request->file('document')->storeAs('pdf', 'invoice_123.pdf', 'local'); The Problem When I try to upload a file, I get this error:

Impossible to create the root directory "X:\project_files\invoices".

Also, when I try to open X: in Windows Explorer, I get a network error saying Windows can't access the drive.

What I've Checked The folder X:\project_files\invoices exists and is writable from my user account.

The network share is accessible from my user session.

The web server runs under the default IIS user.

My Questions How can I make Laravel (running under IIS) access and write to a network drive?

Is there a better way to configure the disk in filesystems.php for a network share?

Do I need to use UNC paths instead of mapped drives?

What permissions or user context should I set for the web server?

Any advice or best practices would be greatly appreciated!

0 likes
5 replies
Glukinho's avatar

Don't use network drives, they live within user profile and are not system-wide. You have to connect network drive (run net use X: \\server\share) from the user your web server/php-fpm service runs as, this is inconvenient and does not bring any advantage.

Use UNC paths:

// config/filesystems.php
'myshare' => [
    'driver' => 'local',
    'root' => '\\\\server\\share\\folder', // don't forget escaping slashes
    // ...
],

// in your code
Storage::disk('myshare')->put('file.txt', $data);

To make IIS have access to the share, you need to save share credentials in the user IIS runs as (local system/network system or some dedicated user).

matbeard's avatar

You can achieve this using symbolic links from Laravel's storage folder to the network shares. You can then create a storage driver for each folder in storage that you've linked to a share.

I've been using this kind of setup for years without issues.

Glukinho's avatar

@matbeard Can you provide a command you use to make such symbolic link? It could be very useful for me. Thanks!

ian_h's avatar

@glukinho You can do this with the mklink command:

mklink /?
Creates a symbolic link.

MKLINK [[/D] | [/H] | [/J]] Link Target

        /D      Creates a directory symbolic link.  Default is a file
                symbolic link.
        /H      Creates a hard link instead of a symbolic link.
        /J      Creates a Directory Junction.
        Link    Specifies the new symbolic link name.
        Target  Specifies the path (relative or absolute) that the new link
                refers to.

A decent explanation for the difference between dir symlinks and junctions can be seen on superuser.com.

1 like
Glukinho's avatar

Thanks a lot! It's a surprise to me a symlink can be pointed to a network path. I thought they exist in local filesystem only.

Please or to participate in this conversation.