SH1989 Posted October 13, 2020 Share Posted October 13, 2020 (edited) Hi All, I am trying to submit multiple form fields, whereby I am asking users to supply specific files. I can get it to upload a single file correctly, however when I increase this to 2 or 3, it's using the same file for all of them. I have used print_r($_FILES) to check everything with the files seems to be OK, and it all looks OK. I need to be able to pair the files, so that's why I haven't used the multiple option. I have tried changing the variables so they are completely different, but I am at a total loss right now. ## First Document if(!empty($_FILES["dc1"])){ $fileName1 = htmlspecialchars_decode((basename($_FILES["dc1"]["name"]))); $fileTypeA1 = pathinfo($fileName1, PATHINFO_EXTENSION); $targetFilePath1 = $uploadDir . $uID . '-' . $randnum . '.' .$fileTypeA1; if(move_uploaded_file($_FILES["dc1"]["tmp_name"], $targetFilePath1)){ $uploadedFile1 = $targetFilePath1; } } ## Second Document if(!empty($_FILES["dc2"])){ $fileName2 = htmlspecialchars_decode((basename($_FILES["dc2"]["name"]))); $fileTypeA2 = pathinfo($fileName2, PATHINFO_EXTENSION); $targetFilePath2 = $uploadDir . $uID . '-' . $randnum . '.' .$fileTypeA2; if(move_uploaded_file($_FILES["dc2"]["tmp_name"], $targetFilePath2)){ $uploadedFile2 = $targetFilePath2; } } Edited October 13, 2020 by SH1989 Clean code up Quote Link to comment https://forums.phpfreaks.com/topic/311592-form-submission/ Share on other sites More sharing options...
Barand Posted October 13, 2020 Share Posted October 13, 2020 https://www.php.net/manual/en/features.file-upload.multiple.php Quote Link to comment https://forums.phpfreaks.com/topic/311592-form-submission/#findComment-1581851 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.