繁体   English   中英

Laravel 8 未找到存储移动文件

[英]Laravel 8 Storage move file not found

我正在尝试将文件从临时路径移动到正确的路径。 但是,无论我尝试什么,它总是会发回此文件未找到错误:

League\Flysystem\FileNotFoundException
File not found at path: var/www/html/storage/app/public/covers/tmp/608c07a082451-1619789728/81-536x354.jpeg

我正在使用sails,因此路径中有'var/www/html/',即使容器中的这条路径没有问题,因为可以从前端获取API到达这条路径,这就是temp文件已保存。

这是 controller 中的代码:

//...
$temp_file = TempFile::where('folder', $cover_folder)->first();
        if ($temp_file) {
            // retrieve file path and target path
            $filepath = storage_path("app/public/covers/tmp/{$temp_file->folder}/{$temp_file->filename}");
            $target_path = storage_path("app/public/covers/{$course->id}/");

            Storage::move($filepath, $target_path);

            $course->cover_img = "{$target_path}/{$temp_file->filename}";
            $course->save();

            // remove temp directory and temp file record
            rmdir(storage_path("app/public/covers/tmp/{$temp_file->folder}/"));
            $temp_file->delete();
        }

此行突出显示的错误回溯:

 Storage::move($filepath, $target_path);

还尝试使用Storage::disk('public')->move() ,或public_storage ,或Storage::path() ,或仅使用纯字符串,都不起作用。

通过运行php artisan storage:link符号链接从public/storage设置为storage

我已经在 laracast、堆栈溢出或 github 上进行了尽可能多的搜索,但无法找到解决方案。 有人对这个问题有任何想法吗?

真的真的很感激。

不要使用 storage_path function 因为方法 Storage::move( 有前缀路径 [app_path]/storage/app/

 Storage::move("public/covers/tmp/{$temp_file->folder}/{$temp_file->filename}", "public/covers/{$course->id}/");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM