Mkdir (): No such file or directory - laravel

I would like to create a directory, but I got this error:

ErrorException in Filesystem.php line 390: mkdir(): No such file or directoryErrorException in Filesystem.php line 390: mkdir(): No such file or directory


 in Filesystem.php line 390
at HandleExceptions->handleError('2', 'mkdir(): No such file or directory', 'C:\xampp\htdocs\yatan\yatan\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php', '390', array('path' => 'C:\xampp\htdocs\yatan\yatan\public/assets/images/projects/1/1476592434/', 'mode' => '511', 'recursive' => false, 'force' => false))

my code is:

    $to_main_image = time();
    $path = 'assets/images/projects/'.$user_id.'/'.$to_main_image.'/';
    File::makeDirectory(public_path().'/'.$path,0777);
+5
source share
2 answers

Change the line

File::makeDirectory(public_path().'/'.$path,0777);

to

File::makeDirectory(public_path().'/'.$path,0777,true);

So subdirectories are also created.

+13
source

if you are using laravel 5.8 try

go to vendor / swiftmailer / swiftmailer / lib / classes / Swift / KeyCache / DiskKeyCache.php and find the prepareCache function and change line No. 247 -

if (!mkdir($cacheDir))
from

before

if (!mkdir($cacheDir,0777,true)) 

I also added a code snippet.

private function prepareCache($nsKey)
    {
        $cacheDir = $this->path.'/'.$nsKey;
        if (!is_dir($cacheDir)) {
            if (!mkdir($cacheDir,0777,true)) {
                throw new Swift_IoException('Failed to create cache directory '.$cacheDir);
            }
            $this->keys[$nsKey] = [];
        }
    }
0
source

Source: https://habr.com/ru/post/1657896/


All Articles