Are you trying to upload multiple files at once ? Here’s how to implement multiple files upload using HTML and PHP.
In this article, I am going to show how to use a single HTML file input to upload multiple files. In addition to that, I will demonstrate using multiple file inputs with additional input fields.
Implementing multiple files upload
Firstly, you need to create a HTML form with attribute enctype=’multiple/form-data’. In fact, the enctype attribute specifies how the form-data should be encoded when submitting it to the server. When you are using forms that have a file upload control, you need to specify enctype as multiple/form-data.
If you are using single file input, you need to enable your file element to select multiple files. In order to do this, you need to name your file input as an array, eg. name=”files” . Also, File Input element must have multiple=”multiple” or just multiple.
As you can see, there is multiple text input and file input controls. By appending ‘’ to your input element names, input elements will submit as arrays.
When you submit the above form, $_POST[‘title’] will be an array. By matching the index of array $_POST[‘title’] with $_FILES[‘fileUpload’][‘name’], you can get corresponding title, filename pair. For instance, $_POST[‘title’] is the title of file $_FILES[‘fileUpload’][‘name’] and so on.
In this way, you can implement multiple file uploads using HTML and PHP.