运行时异常:目录名不能为空

时间:2019-12-17 04:13:14

标签: laravel apache2

在开发服务器上测试我的Laravel项目时(在Debian上为apache2),我遇到问题。

当我尝试在生成所有文件后从一个文件夹中压缩它们时,就会发生这种情况。

在本地环境中一切正常,来自我的apache2服务器和本地服务器的文件树是相同的,并且权限似乎也很好。

当我在堆栈溢出中寻找此错误时,有些人在谈论他们的作曲家和工匠命令不起作用,这对我来说不是事实。

我已经在服务器上运行composer install了,我不知道要看什么。

这是Laravel日志中的错误:

enter image description here

这是我的控制器:

    public function downloadDayMenus($date){
    $folderPath = storage_path('app\public\archived-menus\\'.$date);

    $rootPath = realpath($folderPath);

    $zip = new ZipArchive();
    $zipName = $rootPath.'/'.$date.'-menus.zip';
    $zip->open($zipName, ZipArchive::CREATE | ZipArchive::OVERWRITE);

    // Create recursive directory iterator
    /** @var SplFileInfo[] $files */
    $files = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($rootPath),
        RecursiveIteratorIterator::LEAVES_ONLY
    );

    foreach ($files as $name => $file)
    {
        // Skip directories (they would be added automatically)
        if (!$file->isDir())
        {
            // Get real and relative path for current file
            $filePath = $file->getRealPath();
            $relativePath = substr($filePath, strlen($rootPath) + 1);

            // Add current file to archive
            $zip->addFile($filePath, $relativePath);
        }
    }

    // Zip archive will be created only after closing object
    $zip->close();

    return response()->download($zipName);
}

我的服务器中的树文件(具有权限):

enter image description here

感谢您的帮助!

0 个答案:

没有答案