imhitt's avatar

Select multiple files before upload to server

Hi,

I am building support ticket system and want to give user opportunity to select multiple files but send them after submit form.

after user selected file - do not upload this file to server and show him "add more" button to add other files and save added files after submited form

0 likes
1 reply
aschmelyun's avatar

@imhitt First, you'll want to have a frontend library to handle the "Add More" button, dynamically creating more form inputs. This could be Vue, React, AlpineJS, etc.

Then you could use an array for each of the input names, like this:

<input type="file" name="file[0]">
<input type="file" name="file[1]">
<input type="file" name="file[2]">

And then finally, when you process that data server-side, you can just loop through each of the file requests and store the files:

foreach( $request->file as $file ) {
	$file->store('my/path');
}

Please or to participate in this conversation.