Page 1 of 1

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

Posted: Wed Jun 25, 2008 10:16 pm
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?

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

Posted: Wed Jun 25, 2008 10:27 pm
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.

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

Posted: Thu Jun 26, 2008 10:24 pm
by wlandymore
thanks for the pointer. :)

perfect.