The method you are using is 'old fashioned' 🙂 and you are missing the 'enctype' parameter in the FORM definition.
You will get better results if you access the $HTTP_POST_FILES array after posting.
have a look at this:
<?php
echo '<Pre>';
if (isset($HTTP_POST_FILES['myfile']))
{
if(!isset($HTTP_POST_FILES['myfile']['type']))
{
$HTTP_POST_FILES['myfile']['type'] = "application/unknown";
}
$boundary = uniqid("NewMail7");
$header .= "Content-Type: multipart/mixed;\n boundary=\"$boundary\"\n";
$fp = fopen($HTTP_POST_FILES['myfile']['tmp_name'], "r");
$content=fread($fp, filesize($HTTP_POST_FILES['myfile']['tmp_name']));
if(ereg("text/",$HTTP_POST_FILES['myfile']['type'])) {
$disposition = "inline";
$encoding = "8bit";
} else {
$content = chunk_split(base64_encode($content));
$disposition = "attachment";
$encoding = "base64";
}
$body = "--$boundary\nContent-Type: text/plain\nContent-Transfer-Encoding: 8bit\n\n$ms\n\n";
$body.= "--$boundary\nContent-Type: $userfile_type;\n name=\"$userfile_name\"\nContent-Transfer-Encoding: $encoding\nContent-Disposition: $disposition;\n filename=\"$userfile_name\"\n\n$content\n--$boundary--";
// mail("webmaster@domain.com","Attachment",$body,$headers);
echo $body;
}
else
{
echo '<FORM enctype="multipart/form-data" ACTION="'.$PHP_SELF.'" METHOD=post>';
echo "<INPUT TYPE='hidden' NAME='MAX_FILE_SIZE' VALUE='81000000'>\n";
echo 'Attachment: <input type="file" name="myfile"><BR>';
echo "<input type=submit value='Send'>";
echo '</form>';
}
print_r($HTTP_POST_FILES);
?>