Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :

    $to_main_image = time();
    $path = 'assets/images/projects/'.$user_id.'/'.$to_main_image.'/';
    File::makeDirectory(public_path().'/'.$path,0777);
like image 309
S.M_Emamian Avatar asked Oct 16 '16 04:10

S.M_Emamian


2 Answers

Change the line

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

to

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

So that the sub-directories are also created.

like image 57
Ed Heal Avatar answered Oct 26 '22 06:10

Ed Heal


if using laravel 5.8 then try this out

go to vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php and find prepareCache function and edit line no 247 -

if (!mkdir($cacheDir))

to

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

Adding the code snippet as well.

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] = [];
        }
    }
like image 28
Abhishek Sontakke Avatar answered Oct 26 '22 05:10

Abhishek Sontakke