How to access file uploads in form submissions

Discussion forum for Extension Writers regarding Extension Development.
User avatar
danieltj
Infrastructure Team Member
Infrastructure Team Member
Posts: 520
Joined: Thu May 03, 2018 9:32 pm
Location: United Kingdom
Name: Daniel James

How to access file uploads in form submissions

Post by danieltj »

I'm trying to upload a file (an image, specifically) but I'm running into some issues. Namely I can't get a hold of the file after the form is submitted.

I have this and am trying to contain the file in my variable like so:

Code: Select all

$file_upload = $request->variable( 'my_uploaded_file', [], true, 'FILES' );
But when I dump and die the variable, I get an empty array (the default value I'm setting in the method).

How do I get access to the file I've uploaded? I'm sure this is simple but I'm completely stumped here.

edit:

I've double checked my form tags and I believe my HTML is correct too. I'm not missing the enctype.

Code: Select all

<form action="{{ U_ACTION }}" method="post" enctype="multipart/form-data">
Last edited by Mick on Sat Jul 13, 2024 6:29 am, edited 1 time in total.
Reason: Solved.
đź’· Purchase the Awesome Payments extension today!
Monetise your forum with one off payments and subscriptions.

Need a premium extension created? Send me a PM.
User avatar
danieltj
Infrastructure Team Member
Infrastructure Team Member
Posts: 520
Joined: Thu May 03, 2018 9:32 pm
Location: United Kingdom
Name: Daniel James

Re: How to access file uploads in form submissions

Post by danieltj »

I fixed it.

I needed to use the file method rather than the variable method. Updated code that works:

Code: Select all

$file_upload = $request->file( 'my_uploaded_file' );
Silly me.
đź’· Purchase the Awesome Payments extension today!
Monetise your forum with one off payments and subscriptions.

Need a premium extension created? Send me a PM.

Return to “Extension Writers Discussion”