skip to Main Content

I have a form where the user can upload a file. The file should not be stored in my database.I want to view the contents of a file and then return a response to the user.How can i get the content. If I call by name, it just returns the file name.

  <input type="file" required class="form-control" accept=".xml"id="file" name="file" multiple>
 public function loadData(Request $req) {

        dd($req->input('file'));
}

2

Answers


  1. You can get the contents of the file uploaded using file_get_contents() method. Example:

    file_get_contents($request->file);
    
    Login or Signup to reply.
  2. From Laravel documentation:

    You may retrieve uploaded files from an IlluminateHttpRequest
    instance using the file method or using dynamic properties. The file
    method returns an instance of the IlluminateHttpUploadedFile class,
    which extends the PHP SplFileInfo class and provides a variety of
    methods for interacting with the file.

    public function loadData(Request $req)
    {
        $content = $req->file('file')->get();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search