I’m trying to understand what specifically $key => $tmp_name is doing in the following code:
if(isset($_FILES['files']))
{
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name)
{
echo $_FILES['files']['name'][$key], "\n";
move_uploaded_file($tmp_name, 'img/'.$_FILES['files']['name'][$key]);
}
}
This is how you access your values if you have an upload form that has multiple fields, all named
files[]orfiles[x]wherexis a number:example html:
The confusing thing is that the sent-in values are not grouped by index, but by their property (
error,tmp_name, etc.).Edit: Based on your edit, I would recommend reading up on
foreachandarraysin general.