# PHP - Uploading file and sending via PHP - in a pickle!

**URL:** <https://forum.kirupa.com/t/php-uploading-file-and-sending-via-php-in-a-pickle/303300>\
**Category:** programming\
**Created:** [January 18, 2010, 1:38pm UTC](https://forum.kirupa.com/t/php-uploading-file-and-sending-via-php-in-a-pickle/303300 "2010-01-18T13:38:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fulci](https://avatars.discourse-cdn.com/v4/letter/f/5f9b8f/32.png) [@fulci](https://forum.kirupa.com/u/fulci)\
**Post date:** [January 18, 2010, 1:38pm UTC](https://forum.kirupa.com/t/php-uploading-file-and-sending-via-php-in-a-pickle/303300/1 "2010-01-18T13:38:28Z")

</div>

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:

```auto
<?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
 <?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!
