KISS code with some explanations:
Below is the full functional simple code to get started. You can add error checking, maximum size material, etc. After you get something simple.
The $ _FILES array is a three-dimensional array built into PHP that stores all the information about the downloaded file.
The HTML INPUT tag will have only one element for each <name = 'part.
So, if your INPUT tag looks like this:
<INPUT name="InpFile[]" type="file" />
In the $ _FILES array there will be one element of the top array named "InpFile".
Also notice the [] after InpFile ..... which tells PHP that every time you use an input tag with the same "name", it adds it to the same top element of the $ _FILES array.
Inside this one element there are 5 other elements of the array with the names: 'name', 'type', 'tmp_name', 'error' and 'size'.
And each of these array elements will contain data for each uploaded file.
Your first name of the downloaded file will be in $ _FILES ['InpFile'] ['name'] ['0']
And other information about your first uploaded file will also be the same in the array, for example, the size of the first file will be in $ _FILES ['InpFile'] ['size'] ['0']
Each subsequent file name will be in $ _FILES ['InpFile'] ['name'] [1], $ _FILES ['InpFile'] ['name'] [2] .... etc
After downloading, each file will have a random temporary name in the element $ _FILES ['InpFile'] ['tmp_name'] [0 ... n], which is the name that it uses for the first file upload to the time domain.
SO, after downloading, you must move the files from the time domain to where you want.
This is done using this statement:
move_uploaded_file($_FILES['InpFile']['tmp_name'][$Key], $_FILES['InpFile']['name'][$Key] ) or die("Move from Temp area failed");
In the description below, foreach $ Key and $ Name are only available so that $ Key gets all increasing numbers for each iteration ... i.e. 0, 1, 2 ..... etc., and then you can use $ Key to refer to the name, tmp_name, etc. Each file in the array.
This code allows you to do everything on one page, since the form actually calls itself (action = "") for publication. Therefore, the first time you load the page, you will get an error in the php code because $ _FILES is not installed yet ... therefore all the code is in the If: If ($ _FILES) statement.
After you submit the form, it will do this and then repeat the status for each file after it is moved to your area.
In addition, this code will upload the file to the same directory as the page ... you can change everything using information from other messages in SO.
<FORM action="" method="post" enctype="multipart/form-data"> <P align="center"><B>Choose Files</B><BR> <BR> File One: <INPUT name="InpFile[]" type="file" /> <BR> <BR> File Two: <INPUT name="InpFile[]" type="file" /> <BR> </P> <P align="center"><BR> <INPUT type="submit" name="submit" value="UpLoad"> </P> </FORM> <H3 align="center"> </H3> <H3 align="center">Status:</H3> <P align="center"> </P> <P align="center">
Put this PHP code right here on the same page:
<?php If ($_FILES) { foreach ($_FILES ['InpFile']['name'] as $Key => $Name) { move_uploaded_file( $_FILES['InpFile']['tmp_name'][$Key], $_FILES['InpFile']['name'][$Key] ) or die("Move from Temp area Failed"); $EFileName = $_FILES['InpFile']['name'][$Key]; echo "<P>$EFileName: Uploaded"; } } ?>