Checking if file is valid when uploading in laravel
When uploading files with laravel, I ran into an unexpected problem.
Everything was working fine, and then seemingly suddenly stopped working.
After some poking around, I discovered that the problem was only happening to files getting uploaded from my local 'onedrive/skydrive' folder.
Ok, no problem, I can live with not being able to upload from skydrive...
the problem is, that calling
if (Input::hasFile($entry))
Input::file($entry)->getMimeType()
resulted in an
Symfony\\Component\\Debug\\Exception\\FatalErrorException
being thrown from getMimeType()
I did expect hasFile(...) only to return true if file is a valid file!
after looking into
Symfony\Component\HttpFoundation\File\UploadedFile
i discovered that I could check if the file was valid using
Input::file($entry)->isValid()
so thats basically what we have to do, at least for now.
remember
Input::file($entry)->isValid()
Written by Christian
Related protips
1 Response
If you are experiencing issue in validation, then you will find this tutorial on multiple file upload in Laravel with validation really helpful. According to this tutorial, you will have to add you validation code in Controller file.