2

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:

  1. Laravel retrieve physical file instance onto input file
  2. Laravel - file path to UploadedFile instance

Environment

Following are specifications for my development environment:

  1. Host os: Ubuntu 14.04
  2. Virtual Environment: Vagrant
  3. Server platform: Centos 7.2
  4. Laravel version: Laravel 5.3
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
PseudoAj
  • 5,234
  • 2
  • 17
  • 37

0 Answers0