Kevin W
Kevin W

Reputation: 13

Laravel's Storage::makeDirectory returns mkdir: invalid argument

So I'm trying to create a new directory in C:/..../public/videos folder when somebody uploads a video, using the following code:

if ($request->hasFile('video')) {
    $newDir = public_path('videos\\' . $story->story_id);
    Storage::makeDirectory( $newDir, 0755, true);
    $request->file('video')->move($newDir);
 }

But I get this error:

ErrorException in Local.php line 350: mkdir(): Invalid argument in Local.php line 350 at HandleExceptions->handleError('2', 'mkdir(): Invalid argument', 'C:\xampp\htdocs\qanda2\vendor\league\flysystem\src\Adapter\Local.php', '350', array('dirname' => 'C:\xampp\htdocs\qanda2\public\videos\31', 'config' => object(Config), 'location' => 'C:\xampp\htdocs\qanda2\storage\app\C:\xampp\htdocs\qanda2\public\videos\31', 'umask' => '0', 'visibility' => 'public')) at mkdir('C:\xampp\htdocs\qanda2\storage\app\C:\xampp\htdocs\qanda2\public\videos\31', '493', true) in Local.php line 350 at Local->createDir('C:\xampp\htdocs\qanda2\public\videos\31', object(Config)) in Filesystem.php line 259 at Filesystem->createDir('C:\xampp\htdocs\qanda2\public\videos\31') in FilesystemAdapter.php line 276

It seems like makeDirectory automatically adds C:\xampp\htdocs\qanda2\storage\app\ in front of my path.

Is there any workaround for this? I've been struggling with this for a while now and I can't find anything about this issue.

Upvotes: 1

Views: 4564

Answers (1)

Imtiaz Pabel
Imtiaz Pabel

Reputation: 5443

To create a directory, you should use File, like this:

if ($request->hasFile('video')) {
   $newDir = public_path('videos\\' . $story->story_id);
   File::makeDirectory( $newDir, 0755, true);
   $request->file('video')->move($newDir);
}

Upvotes: 3

Related Questions