storage_path('/app/public/') 到底位于哪里

问题描述 投票:0回答:2

我想通过命令行运行此代码:

public function handle()
    {
        if ( ! File::exists(storage_path('/app/public/examResult/' . $this->argument('file'))) ) {
            dd('Not found this file!');
        }

        Excel::import(new ImportsExamResultImport(), storage_path('/app/public/examResult/' . $this->argument('file')));

        dd('Import excel was successfully');
    }

所以它基本上读取位于

storage_path('/app/public/examResult/')
目录的 Excel 文件。

所以我将 Excel 文件放在

laravelproject/app/public/examResult
,但是当我运行命令来执行它时,我收到以下消息:

未找到此文件!

所以问题是,

storage_path
到底在哪里?我是否将文件放在正确的位置?

php laravel laravel-5.8
2个回答
2
投票

当您设置一个新项目时,您将想要运行:

php artisan storage:link

这建立了从 laravelproject/public/storage 到 laravelproject/storage 的符号链接

storage_path('/app/public')

可以在以下位置找到:

laravelproject/storage/app/public

0
投票

在config/filesystems.php中配置文件上传路径

'默认' => env('FILESYSTEM_DISK', '公共')`

public - 想要存储文件的位置,请参考更多信息(本地,s3...)

然后运行: php artisan storage:link 您可以通过

查看上传的文件

laravel项目名称/存储/应用程序/公共/{文件名}

在刀片文件中,您可以通过以下方式访问:

asset('storage')
/ {文件名}

更多信息请参考https://laravel.com/docs/10.x/filesystem

© www.soinside.com 2019 - 2024. All rights reserved.