Scenario
I am working on a project where csv
files are uploaded and processed. Following is a use case:
- Task 1: User A can upload
data.csv
using interface or ftp - Task 2: User B selects a certain
csv
file from UI and process it
Problem
File upload is an easier task. I have a form and using storeAs
method to store the data.
$thisFltFile->storeAs($directory,$file);
Now I have another form to achieve Task 2
where User B
selects the file names in the $directory
listed using:
$filelist = Storage::allFiles($directory);
When the user submits the form, it triggers a method in controller
where I want to validate the file before processing it from the file path since the files can be uploaded from ftp
too. For example:
$rules = array('file' => 'required|file|mimetypes:text/plain|mimes:txt,dat,csv',);
$this->validate($file,$rules);
Explored
Unfortunately, there isn't a File
facade with Laravel 5.3 which can retrieve the file instance from the path like here. I have tried Storage::get($path)
but it seems to retrieve the file contents.
Additionally following have been explored:
- Laravel retrieve physical file instance onto input file
- Laravel - file path to UploadedFile instance
Environment
Following are specifications for my development environment:
- Host os: Ubuntu 14.04
- Virtual Environment: Vagrant
- Server platform: Centos 7.2
- Laravel version: Laravel 5.3