con*_*s39 1 php laravel flysystem
我正在尝试将文件从临时路径移动到正确的路径。但是,无论我尝试什么,它总是发回此文件未找到错误:
League\Flysystem\FileNotFoundException
File not found at path: var/www/html/storage/app/public/covers/tmp/608c07a082451-1619789728/81-536x354.jpeg
Run Code Online (Sandbox Code Playgroud)
我正在使用 sail,因此路径中有 'var/www/html/',即使容器中的此路径没有问题,因为可以从前端获取 API 到达此路径,这就是 temp 的方式文件已保存。
这是控制器中的代码:
//...
$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();
}
Run Code Online (Sandbox Code Playgroud)
此行突出显示的错误回溯:
Storage::move($filepath, $target_path);
Run Code Online (Sandbox Code Playgroud)
还尝试使用Storage::disk('public')->move()、 或 、public_storage或Storage::path()、 或仅纯字符串,但均无效。
通过运行将符号链接设置为从public/storage到。storagephp artisan storage:link
我在 laracast、stackoverflow 或 github 上进行了尽可能多的搜索,但无法找到解决方案。有人对这个问题有任何想法吗?
真的真的很感激。
小智 6
不要使用 storage_path 函数,因为方法 Storage::move( 具有前缀路径 [app_path]/storage/app/
Storage::move("public/covers/tmp/{$temp_file->folder}/{$temp_file->filename}", "public/covers/{$course->id}/");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4323 次 |
| 最近记录: |