I’ve done this many times in the past but am drawing a blank now on how to make it work. File uploads are working with details about the upload that I can get from the $_FILES array, such as the file name name, being inserted into the database as a record of the upload but I need to post other information along with it from the $_POST and that’s where I’m having difficulty wrapping my head around. Partially because this time my sites have a function that generates the prepared statement from the array (filtering out what is not needed) but also because I’ve not done it in many years.
It seems to me that I need to merge the $_POST and $_FILES together into a single array which I have done, then work from there but before I go too far, I need to be sure that this is the proper way or at least an acceptable way, especially as I notice that the tmp file name uses different naming convention than it has when reading the $_FILES array alone. It was never preceded by php before.
Incidentally, I’ve never concatenated arrays together this way but found it online and thought I would give it a test. It was a surprise that it actually worked!
Combining them with this:
$FileArray = $_POST + $_FILES;
$FileArray = array_flatten($FileArray);
gives this:
Array
(
[PageUse] => 19
[ImageCaption] => This is a test
[SortOrder] => 7
[files] => Upload File(s)
[name] => 00-00_0021.jpg
[full_path] => 00-00_0021.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpNtcSSx
[error] => 0
[size] => 3463396
)