how can I get multiple input fields to work with this form?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wlandymore
Forum Newbie
Posts: 2
Joined: Wed Jun 25, 2008 10:10 pm

how can I get multiple input fields to work with this form?

Post by wlandymore »

I'm playing around with an image uploader so I can send some images to a server. I have it working properly with one field, but I'm not sure how to add multiple fields and then get all of the images to go at one time.

Here's the code I'm using right now:

<?php
if ($_REQUEST[completed] == 1) {
$newname = uniqid("file").".jpg";
move_uploaded_file($_FILES['mailfile']['tmp_name'],
"uploads/$newname");
} ?>

<html>
<head><title>Uploader</title></head>
<body><h1>Uploader</h1>
<?php if ($_REQUEST[completed] != 1) { ?>
<b>Please upload images below</b><br>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=1500000>
<input type=hidden name=completed value=1>

Choose files to send: <br />

<input type=file name=mailfile><br />




<input type=submit value="upload"></form>
<?php } else { ?>
<b>Upload Successful!</b>
<?php } ?>

</body></html>

Can anyone tell me how to have multiple fields with only one submit button so they all get uploaded at once?
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: how can I get multiple input fields to work with this form?

Post by Zoxive »

http://www.google.com/search?q=php+mult ... le+uploads

Notice the brackets. Just add more of this line for how many you want to be able to upload.

Code: Select all

 <input type="file "name="mailfile[]"> 
Now you need to have php loop threw the files, because mailfile is now going to be an array.
wlandymore
Forum Newbie
Posts: 2
Joined: Wed Jun 25, 2008 10:10 pm

Re: how can I get multiple input fields to work with this form?

Post by wlandymore »

thanks for the pointer. :)

perfect.
Post Reply