Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

php multiple file upload and insert into table problem

Hi Everybody

Does anyone know how to upload multiple files and insert into db table?

I just know that there is a thing e.g. <input type="file" name="uploads[ ]" /> but i don't know how to get the data from the uploads[ ] and then insert into table to specific rows correctly.

1 Answer

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Are you talking about inserting them into a database table?

If you have your HTML inputs set up as an array with a name of "uploads", then the $_POST["uploads"] variable should be an array that you can loop through, something like this:

foreach ($_POST["uploads"] as $upload) {

    // insert $upload into database 

}

Inside the foreach loop, you do the same thing you would do if you only had one upload.

Does that help?