Using Input :: all () when uploading files in laravel 4.2
According to this , if you do the following
<?php
// app/routes.php
Route::get('/', function()
{
return View::make('form');
});
Route::post('handle-form', function()
{
var_dump(Input::all());
});
We get the following:
array(0) { }
According to Dayle Rees, this is because the files are stored in the $ _FILES array, not in $ _GET or $ _POST. So when we change the second function to:
Route::post('handle-form', function()
{
var_dump(Input::file('book'));
});
We get:
object(Symfony\Component\HttpFoundation\File\UploadedFile)#9 (7) {<
["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=><
bool(false)<
["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=><
string(14) "codebright.pdf"<
["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=><
string(15) "application/pdf"<
["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=><
int(2370413)<
["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=><
int(0)<
["pathName":"SplFileInfo":private]=><
string(36) "/Applications/MAMP/tmp/php/phpPOb0vX"<
["fileName":"SplFileInfo":private]=><
string(9) "phpPOb0vX"<
}<
However, in my project, when I use Input :: all (), I still get the correct output, very similar to the one above. The file I used is different, but I hope you get the point. Why are my projects giving different results from the book?
+3
source to share
1 answer
If you see in /vendor/laravel/framework/src/Illuminate/Http/Request.php,
/**
* Get all of the input and files for the request.
*
* @return array
*/
public function all()
{
return array_replace_recursive($this->input(), $this->files->all());
}
which contains both files and other inputs. Since CodeBright was launched with laravel 3, ( http://goo.gl/NWltLh ) I suppose (but not sure) this section of code was updated later to Laravel 4.
+3
source to share