Laravel 5.5 read a file from the local disk

master picture master · Jan 25, 2018 · Viewed 10.8k times · Source

I am trying to import a csv file with Laravel 5.5 from the local file location. For some reason it can't find the file on my computer however the path is correct.

$fileLocation = $request->file('file')->store('csv');
$importFile = File::file(storage_path('app/' . $fileLocation));

Answer

user9266304 picture user9266304 · Jan 25, 2018

You can use the Storage facade for this. Here is an example:

if (Storage::disk($disk)->exists($filename)) {
    return Storage::disk($disk)->get($filename);
}

throw new FileNotFoundException(sprintf('File not found: %s', $filename), 404);