phplaravel-5.4laravel-5.5laravel-requestlaravel-filesystem

Laravel 5.5 read a file from the local disk


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));

Solution

  • 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);