How to get file properties from a post request using Slim?

How to get file properties from a post request using Laravel & Slim

  • I'm using Laravel + Slim to build an application. I have a form with file upload and I managed successfully to get the information from text inputs: $request = $app->request; $title = $request->post('title'); But how I can get the properties like size, name, tmp_name, etc. from a file input? I found http://stackoverflow.com/questions/28457734/how-to-get-uploaded-files-tmp-name-in-laravel-5-0 question and tried like that but I get this error: Fatal error: Call to undefined method Slim\Http\Request::file()

  • Answer:

    There is couple of method you can apply while you uploading some file(s) using laravel's. Here is the couple of them and most important to, in my thought. $request->hasFile('file_name') hasFile method to check user upload file or not. $request->file('file_name')->isValid() isValid method take care to check file have no error. After these checks, you have to get file properties and move to desired location. For these purposes. $document = $request->file('file_name'); Get the document information object. So after that you can use further helper function provided my laravel FileUploader. $document->getRealPath(); $document->getClientOriginalName(); $document->getClientOriginalExtension(); $document->getSize(); $document->getMimeType(); and finally to move the uploaded file $document->move($destinationPath); $document->move($destinationPath, $fileName); update However if you using slim to upload file, you have to use native php methods like globals Files array to get file and move_uploaded_file to move file and like so. If you still have any question related to upload a file or file validation let me know.

Nicu Vlad at Stack Overflow Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.