mkdir(): 没有那个文件或目录 - laravel

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40066884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:37:21  来源:igfitidea点击:

mkdir(): No such file or directory - laravel

laravellaravel-5

提问by S.M_Emamian

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);

回答by Ed Heal

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.

这样子目录也被创建了。

回答by Abhishek Sontakke

if using laravel 5.8 then try this out

如果使用 laravel 5.8 然后试试这个

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

转到 vendor/swiftmailer/swiftmailer/lib/classes/Swift/KeyCache/DiskKeyCache.php 并找到 prepareCache 函数并编辑第 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] = [];
        }
    }