Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MorganRowse's avatar

File stored in $_FILES but not accessible via $request->all()

Hi all, Currently confused as where my file uploads have been disappearing to. It seems to work with one file but not multiple with different names. The $_FILES superglobal can still see all files.

I have tried to name the inputs using arrays but end up with the same error ie: attachment[0][1] etc

View

<form method="POST" action="{{route('questionnaires.answer',$questionnaire->id)}}" accept-charset="UTF-8" enctype="multipart/form-data">
...
<input name="attachment_1_0" type="file"/>
<input name="attachment_1_1" type="file"/>
...
</form>

Controller using Request class

public function answer(Request $request, Questionnaire $questionnaire)
    {
        dd($request->all());
    }

Returns

array:2 [▼
  "_token" => "e7v7ZxaKoIFGIYOscCAFwsoB8olw8lrNjwx8Azyi"
  "attachment_1_0" => UploadedFile {#229 ▼
    -test: false
    -originalName: "db.png"
    -mimeType: "image/png"
    -size: 86110
    -error: 0
    #hashName: null
    path: "C:\xampp\tmp"
    filename: "phpF4F4.tmp"
    basename: "phpF4F4.tmp"
    pathname: "C:\xampp\tmp\phpF4F4.tmp"
    extension: "tmp"
    realPath: "C:\xampp\tmp\phpF4F4.tmp"
    aTime: 2017-08-15 10:00:06
    mTime: 2017-08-15 10:00:06
    cTime: 2017-08-15 10:00:06
    inode: 0
    size: 86110
    perms: 0100666
    owner: 0
    group: 0
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
    linkTarget: "C:\xampp\tmp\phpF4F4.tmp"
  }
]

Controller using $_FILES superglobal

public function answer(Request $request, Questionnaire $questionnaire)
    {
        dd($_FILES);
    }

Returns

array:2 [▼
  "attachment_1_0" => array:5 [▼
    "name" => "BlackBoard BS Logo.jpg"
    "type" => "image/jpeg"
    "tmp_name" => "C:\xampp\tmp\phpD72F.tmp"
    "error" => 0
    "size" => 88788
  ]
  "attachment_1_1" => array:5 [▼
    "name" => ""
    "type" => ""
    "tmp_name" => ""
    "error" => 4
    "size" => 0
  ]
]

Any help would be greatly appreciated!

0 likes
5 replies
MorganRowse's avatar

@IgorBabko

File storage and manipulation is handled later in the controller action, just unsure why the file is shown in $_FILES and not in $request->all()

IgorBabko's avatar

@MorganRowse $request->all() doesn't show uploaded files. It's intended behavior of the framework.

To access items from $_FILES, $request->file() method should be used.

MorganRowse's avatar

@IgorBabko

dd($request->all());

the return shows

"attachment_1_0" => UploadedFile {#229 ▼
    -test: false
    -originalName: "db.png"
    -mimeType: "image/png"
    -size: 86110
    -error: 0
    #hashName: null
    path: "C:\xampp\tmp"
    filename: "phpF4F4.tmp"
    basename: "phpF4F4.tmp"
    pathname: "C:\xampp\tmp\phpF4F4.tmp"
    extension: "tmp"
    realPath: "C:\xampp\tmp\phpF4F4.tmp"
    aTime: 2017-08-15 10:00:06
    mTime: 2017-08-15 10:00:06
    cTime: 2017-08-15 10:00:06
    inode: 0
    size: 86110
    perms: 0100666
    owner: 0
    group: 0
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
    linkTarget: "C:\xampp\tmp\phpF4F4.tmp"
  }

as per question I'm asking why it doesn't return an empty result with error 4 as with $_FILES.

ie if you have

<input type="number" name='bar'/>

$request->all() will show the input with an empty value. Why do files not return with an empty value?

Sorry for any confusion

IgorBabko's avatar

@MorganRowse I'm not sure but supposedly $request->all() only fetches data from GET query string and POST request body. Files happen to be a different type of content which is place in $_FILES.

Please or to participate in this conversation.