Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Krlinhos's avatar

Path for makeDirectory

Hello!

I try to create a directory in my proyect.

    $folder = 'promo_' . $id;
    $path = base_path() . '/resources/promos/' . $folder;
        Storage::makeDirectory($path, 0777, true);

But when I go to resources/promos/promo_1, there is nothing... :( I can't create directory in these path?

In my app when an user create a promo, the controllore first have to create a Directory and next put in a few files (These files are views, js and css)

Thanks

0 likes
12 replies
bestmomo's avatar

Hello,

That should work, but what is Storage ?

What are permissions on resources folder ?

bestmomo's avatar

If you use Storage the default path is "storage\app" (set in filesystems.php). Why dont you simply use Laravel FileSystem for local ?

Krlinhos's avatar

In laravel 5.1 the alias is Storage or not?

use Storage;

If I try

use Fylesystem;

I retrieve a error.

bestmomo's avatar

For basic Laravel file system the syntax is :

use File;
Krlinhos's avatar

Not work.

use File;

and next in function controller I use

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

But not work :(

Krlinhos's avatar

I retrieve this error:

ErrorException in Filesystem.php line 337: mkdir(): Permission denied

JEYCDEE's avatar

Try next.

At very top under namespace write:

use File;

Then in your method use:

$folder = 'promo_' . $id;
$path = base_path('resources/promos/' . $folder . '/');
File::makeDirectory($path, 0777, true, true);

The base_path function takes an argument if you want to go further then this folder.

dhcmega's avatar

Worked for me with File, amazing that Storage returns TRUE, but it doesn't work. Thanks

Please or to participate in this conversation.