My first post so be gentle! I’ve tried searching for this and there are many similar posts, but I can’t seem to find anything exactly like my problem and I have been at this for hours! :-/
I’m building a system in PHP (5.3) and MySQL and part of the functionality is that a user is required to upload some files based on some previous selections. An example form is as follows:
<form action="" method="post" enctype="multipart/form-data" id="uploadFiles">
<p>
<label for="file1">Upload file 1:</label>
<input type="file" name="file1" id="image">
</p>
<p>
<label for="file2">Upload file 2:</label>
<input type="file" name="file2" id="image2">
</p>
<p>
<input type="submit" name="upload" id="upload" value="Upload">
</p>
</form>
In this instance the user is required to upload two different documents. This all works for me and I can save the 2 files to the server and then insert 2 records to a table in the database with the file name, file type (pdf, jpg) and user id etc by looping through “$_FILES” in my Upload class.
What I am trying to do however is somehow add the name attribute <input name="foo"> to the inserted row so that “File 1” would have “file1” in a column called document_type and “File 2” would have “file2”. That way I can do a basic check in MySQL to see if the user has uploaded the appropriate files.
To cut to the chase, is there a way to assign or associate the INPUT “name” attribute to each file in $_FILES in my Upload class so that when when I loop through $_FILES, there is a unique document_type?
Please let me know if you require further information regarding my setup.
Output