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
Related Q & A:
- How To Get File Server Free?Best solution by engadget.com
- How to change folder properties inside a sharepoint library?Best solution by SharePoint
- How to get nearest address of a random latitude and longitude?Best solution by Stack Overflow
- How to get custom firmware for a PSP Slim?Best solution by Yahoo! Answers
- How is .txt file different from a .dat file in C?Best solution by mycplus.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.