[英][ Laravel 5.2 ]Storage file not found even if it exists
\Storage::disk('verify_files')->put('verify-' . $fileCode[3], $fileCode[0]);
$attach = \Storage::get(storage_path('app/public/verify') . '/' . 'verify-' . $fileCode[3]);
我正在使用上面的代碼來生成和獲取文件。
這是我使用的文件系統:
'verify_files' => [
'driver' => 'local',
'root' => storage_path('app/public/verify'),
'visibility' => 'public',
],
當我使用file_exists()測試它時,它返回true,但是laravel FileNotFoundException in FilesystemAdapter.php line 61:
返回FileNotFoundException in FilesystemAdapter.php line 61:
我在這里想念什么嗎?
Storage Facade的get
方法將自動查看默認磁盤的目錄。 在這種情況下,您將使用storage_path
傳遞文件的絕對路徑,這是多余的,因為它將按原樣在storage/app
目錄中查找。
而是執行Storage::disk('verify_files')->get('verify-' . $fileCode[3])
;;
當您需要文件和目錄的絕對路徑時,請使用storage_path
。
除了您一直在使用其他方法之外,我遇到的錯誤與您相同:
$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);
這來自此頁面的組合,並且上述@SArnab提到的路徑不必是絕對的。
除了我使用不同的方法外,我以前唯一的問題是我使用的是絕對路徑,而不是現在使用的相對路徑。
我只是以為我會在Laravel 5.2中添加這種替代方法來獲取文件內容。
請享用!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.