Laravel 10 404 尝试在 Windows 10/IIS 上下载现有文件时出错

Laravel 10 404 error trying to download existing files on Windows 10/IIS

提问人:kirkaracha 提问时间:11/11/2023 更新时间:11/11/2023 访问量:11

问:

我在 Windows 10/SQL Server 上使用 IIS 在 Laravel 10 中下载现有文件时遇到 404 错误。

文件存储在具有 UUID 和 folder_id的文件表中。文件夹的路径存储在文件夹表中。

Files table

Folders table

页面上的下载链接转到 FileController 中的 show 函数,并将 UUID 作为参数。FileController 使用特征获取文件夹的存储路径并附加文件名,然后应下载文件。

文件控制器:

    public function show(File $file): StreamedResponse
    {
        return $this->download($file);
    }

文件特征:

    public function download(File $file): StreamedResponse
    {
        $folder = $file->folder()->first();

        $folderPath = $this->getFolderPath($folder); // [in FolderTrait]

        \Log::debug('download folderPath: ' . $folderPath);

        $storagePath = $this->getStoragePath($folderPath);

        \Log::debug('download storagePath: ' . $storagePath);

        $path = join(DIRECTORY_SEPARATOR, [$storagePath, $file->filename]);

        \Log::debug('download path: ' . $path);

        if (file_exists($path) === false) {
            $this->logInfo("File $file->filename not found at $path");

            abort(Response::HTTP_NOT_FOUND);
        }

        return Storage::disk('local')->download($path, $file->filename, [
            'Content-Type' => $file->mime_type
        ]);
    }

文件夹特征:

    public function getFolderPath(Model $folder): string
    {
        return $folder->path;
    }

    public function getStoragePath(string $path): string
    {
        $storagePath = storage_path('app' . DIRECTORY_SEPARATOR . $path);

        return str_replace('/', DIRECTORY_SEPARATOR, $storagePath);
    }

当我单击下载链接时,我收到 404 错误。我希望下载文件,因为生成的路径是正确的,文件存在于服务器上,并且 Web 用户有权读取该文件。

日志:download path: C:\inetpub\the-anchor-bridge\storage\app\knowledge-base\policies\human-resources-policies\employee-policy-book.pdf

File employee-policy-book.pdf not found at C:\inetpub\the-anchor-bridge\storage\app\knowledge-base\policies\human-resources-policies\employee-policy-book.pdf

该文件存在于该路径的服务器上:File in directory

IUSR 和 IIS_USRS 具有读取权限:

enter image description here enter image description here

文件 下载 HTTP-STATUS-CODE-404 LARAVEL-10

评论


答: 暂无答案