troubleshooting Question

Upload multiple files from multiple inputs with PHP and insert the filename into a database.

Avatar of Joey Drenth
Joey Drenth asked on
26 Comments1 Solution135 ViewsLast Modified:
I want to upload multiple files to my server with PHP and insert the filename, given description and some other things to my database.

This is the form I am using. I am using the LI and UL elements because I am using jQuery to add more inputs dynamically.

            <form class="add-post-form" action="add-files-to-post.php?id=<?php echo $lastId; ?>" method="post">
              <ul id="fieldList">
                  <input type='file' name='postFile'>
                  <input type='text' name='postName[]' placeholder='Titel van bestand'>
                  <input type='text' name='postDesc[]' placeholder='Beschrijving / instructie'>
              <button type="button" id="addMore" name="button">Nog een bestand</button>
              <input type="submit" name="" value="Bestanden uploaden en toevoegen">

This is the jQuery code

$(function() {
  $("#addMore").click(function(e) {
    $("#fieldList").append("<li><input type='file' name='postFile'></li>");
    $("#fieldList").append("<li><input type='text' name='postName[]' placeholder='Titel van bestand'></li>");
    $("#fieldList").append("<li><input type='text' name='postDesc[]' placeholder='Beschrijving / instructie'></li>");

This is how my table looks

Along with this, I am of course using some CSS to remove the bullet points and do some additional styling.

My question

How can I upload the files, while ALSO inserting the filepath, file title and file description into my database?

Using a loop seems the most logical option? However I am unsure on how to implement it.

I have tried a script that would upload multiple files from one <input> tag with the attribute multiple but this is not what I am looking for since I need to be able to add a title and description for each individual file.

Any help and tips are greatly appreciated. I know it's a broad question, but I just need someone to give me a point to start at.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 26 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 26 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros