Hey all, I’m in a pickle here with a tiny bit of PHP. I have a code which allows users to upload a file, write a message, and then it off to whoever. However, I really need the option of up to three files being upload, while the PHP only recognizes the first file sent. Can anyone see what I need to add/tweak. I’m losing the battle here with this thing!:hurt:
In the body tag I have:
<?php echo $output; ?>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" <?php echo $flags;?>>
<p><label for="message">Please type the name you previously entered in the Personal Details section:</label><br />
<textarea name="message" id="message" cols="26" rows="2"></textarea></p>
<p><label for="file">Please attach your main profile picture:</label><br />
<input type="file" name="file" id="file"></p>
<p><label for="file">Please attach a furher (optional) picture:</label><br />
<input type="file" name="file" id="file"></p>
<p><label for="file">Please attach a furher (optional) picture:</label><br />
<input type="file" name="file" id="file"></p>
<p><input type="submit" name="submit" id="submit" value="send"></p>
</for
And the PHP is:
<?php
if(isset($_POST['submit']))
{
//The form has been submitted, prep a nice thank you message
$output = '<h1>Thank you. Your sign-up is now complete.</h1>';
//Set the form flag to no display (cheap way!)
$flags = 'style="display:none;"';
//Deal with the email
$to = 'name@name.com';
$subject = 'profile picture email';
$message = strip_tags($_POST['message']);
$attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
$filename = $_FILES['file']['name'];
$boundary =md5(date('r', time()));
$headers = "From: webmaster@example.com
Reply-To: webmaster@example.com";
$headers .= "
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=\"_1_$boundary\"";
$message="This is a multi-part message in MIME format.
--_1_$boundary
Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
--_2_$boundary
Content-Type: text/plain; charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit
$message
--_2_$boundary--
--_1_$boundary
Content-Type: application/octet-stream; name=\"$filename\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--_1_$boundary--";
mail($to, $subject, $message, $headers);
}
?>
Any help will GREATLY be appreciated!