Before reading: The first few paragraphs of this question are me explaining the context of the situation in detail. Please skip to "The Question" at the bottom if you would just like to answer the question.
I'm currently working on a feature for a website that allows users to upload and share professional documents. These include documents like .doc,.txt,.xlsx,.pdf,ect...
Before uploading the documents, the user will be able to rename them if they so choose to. This is meant to help other users find the file so that it will be renamed to something like "psychologyStatistics.docx" instead of something confusing like "Johns_File.docx".
I have form setup...
<form name="uploadFiles" action="submitFiles.php">
<input type="file" name="file_input" multiple>
<input type="submit">
</form>
Notice the multiple.
I also have a dynamic list of text fields that the user will use to rename the files. This is done using a bit of javascript but I'm not going to post it here because its rather confusing and not helpful to the problem.
Unfortunately, i cannot simply rename the files in javascript like so:
object.files[].name = newName; // cannot be done because .name is read-only
The issue: I need to move the array of files to PHP WITH another two dimensional array of user-input file names. PHP somehow needs to know what files are connected to what file names. Therefore i will connect them using PHP's $_FILES['file']['name']
with javascript's object.files[].name
. I will do this by passing a two dimensional array with the object.files.name
as field 1 and newNames
as field 2.
The Question: How can i pass a two-dimensional string array in a form input field using JavaScript or other necessary tools? Something like <input type="text" name="names[][]" multiple>
would work perfectly however this is obviously not possible. If a 2-dimensional array is 100% impossible, then a one-dimensional array might work too.
Thanks guys. If anything needs clarifying then go ahead and ask.
EDIT: Javascript is going to grab text fields from a separate form and add them into a new input field inside the primary upload form. The issue is actually getting them into the primary upload form in an organized and relatively clean manner. Therefore I was looking at doing a 2-dimensional array.
name="foo[bar]"
in PHP you can get it as$_POST['foo']['bar']
. In Javascript you're still setting a field name so you would set the field name the same way. Maybe that will point you in the right direction, as it stands I'm not clear on how the users are renaming files. Try showing some more code. – Cfreak 2 days ago