Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Laravel Input::hasfile() work on input arrays?

I'm working on a Laravel project that uses a form with multiple file inputs. If I submit the form with the first input empty and all other inputs with a file, then hasFile returns false. It will only return true if the first input contains a file.

if(Input::hasfile('file'))
{
 // do something
}

This is the input array via Input::file('file). The small image input is empty, but the large is not. I'd like it to look at the whole array and if there any files present, then proceed with the "do something".

Array
(
    [small] => 
    [large] => Symfony\Component\HttpFoundation\File\UploadedFile Object
        (
            [test:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 
            [originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image_name.jpg
            [mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg
            [size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 44333
            [error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
            [pathName:SplFileInfo:private] => /Applications/MAMP/tmp/php/phpHILgX2
            [fileName:SplFileInfo:private] => phpHILgX2
        )

)

Is this expected behavior? Or, should it be looking at the entire array?

like image 772
MAZUMA Avatar asked Nov 30 '22 02:11

MAZUMA


1 Answers

You can check by using the array key for example like below :- HTML Input type File Element :

<input type="file" name="your_file_name[]" />

Laravel 5 : $request->hasFile('your_file_name.'.$key)

Laravel 4.2 : Input::hasFile('your_file_name.'.$key)

like image 129
Ronak Shah Avatar answered Dec 05 '22 00:12

Ronak Shah