Php [Laravel 5.2]未找到存储文件,即使它存在
我正在使用上面的代码生成和获取文件 以下是我使用的文件系统:Php [Laravel 5.2]未找到存储文件,即使它存在,php,laravel,storage,file-not-found,Php,Laravel,Storage,File Not Found,我正在使用上面的代码生成和获取文件 以下是我使用的文件系统: \Storage::disk('verify_files')->put('verify-' . $fileCode[3], $fileCode[0]); $attach = \Storage::get(storage_path('app/public/verify') . '/' . 'verify-' . $fileCode[3]); 当我用file_exists()测试它时,它返回true,但laravel在Fi
\Storage::disk('verify_files')->put('verify-' . $fileCode[3], $fileCode[0]);
$attach = \Storage::get(storage_path('app/public/verify') . '/' . 'verify-' . $fileCode[3]);
当我用file_exists()测试它时,它返回true,但laravel在FilesystemAdapter.php第61行返回FileNotFoundException:
我在这里遗漏了什么吗?存储门面的
get
方法将自动查找默认磁盘的目录。在这种情况下,您将使用storage\u path
传入文件的绝对路径,这是多余的,因为它将按原样查看storage/app
目录
相反,请执行以下操作:Storage::disk('verify_files')->get('verify-'。$fileCode[3])
当您需要文件和目录的绝对路径时,请使用
storage\u path
。我收到的错误与您相同,只是我使用了不同的方法:
'verify_files' => [
'driver' => 'local',
'root' => storage_path('app/public/verify'),
'visibility' => 'public',
],
这是由于@SArnab上面提到的路径不需要是绝对的时和的组合
除了使用不同的方法之外,我以前遇到的唯一问题是我使用的是绝对路径,而不是我现在使用的相对路径
我只是想在Laravel5.2中添加这个替代方法来获取文件内容
享受吧 我传递了路径,而不是使用存储外观,并从那里处理它。当你的答案有效时,我会更新你。谢谢快一个月了,我忘了更新。问题是->get()获取内容。我用类似于存储路径(“app/public/verify”)的东西获取文件。"/" . $如果有更好的解决方案,请告诉我!
$parse = new Parsedown();
$url = url('about.md'); // This would fail, because it returns absolute
$url = 'about.md'; // the file is living in the root directory of public. This would succeed, because it's relative
try { // catch file not found errors
$about = File::get($url);
} catch (Illuminate\Filesystem\FileNotFoundException $exception) {
die ('Bad File');
}
echo $parse->text($about);