I would like to point out before I get into this that I am a PHP newb, and I have been struggling for a while with this before finally deciding that I don't know what I'm doing with it. I don't think I misspelled anything or mis-capitalized like [this guy](https://stackoverflow.com/questions/1882052/why-does-file-get-contents-return-the-error-filename-cannot-be-empty "this guy") but, please forgive my messy code.

```
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_comment = $_POST['comment'];
$field_question = $_POST['question'];
$field_support = $_POST['support'];
$field_steam = $_POST['steam'];
$field_file = $_POST['file'];
$field_message = $_POST['message'];
//Get the uploaded file information
$name_of_uploaded_file = basename($_FILES['uploaded_file']['name']);
//get the file extension of the file
$type_of_uploaded_file = substr($name_of_uploaded_file, strrpos($name_of_uploaded_file, '.') + 1);
$size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;//size in KBs
//Settings
$max_allowed_file_size = 10000; // size in KB
$allowed_extensions = array("doc", "docx", "txt", "pdf", "rtf", "otf");
//Validations
if($size_of_uploaded_file > $max_allowed_file_size )
{
$errors .= "\n Size of file should be less than     $max_allowed_file_size";
}
//------ Validate the file extension -----
$allowed_ext = false;
for($i=0; $i<sizeof($allowed_extensions); $i++)
{
if(strcasecmp($allowed_extensions[$i],$type_of_uploaded_file) == 0)
{
$allowed_ext = true;
}
}
if(!$allowed_ext)
{
$errors .= "\n The uploaded file is not supported file type. ".
" Only the following file types are supported: ".implode(',',$allowed_extensions);
}

//copy the temp. uploaded file to uploads folder
$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
if(is_uploaded_file($tmp_path))
{
if(!copy($tmp_path,$path_of_uploaded_file))
{
$errors .= '\n error while copying the uploaded file';
}
}

$to = 'me@myemail.com';
$subject = 'Contact Form Message from '.$field_name;
$attachment = chunk_split(base64_encode(file_get_contents($path_of_uploaded_file)));

$boundary = md5(date('r', time())); 

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message Type: '." ";
$body_message .= ''.$field_comment." ";
$body_message .= ''.$field_question." ";
$body_message .= ''.$field_support." ";
$body_message .= ''.$field_steam."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$boundary."\""; 

$mail_status = mail($mail_to, $subject, $attachment, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'contact.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to me@myemail.com');
window.location = 'contact.html';
</script>
<?php
}
?>

```

And I keep getting this error:

Warning: file\_get\_contents() [function.file-get-contents]: Filename cannot be empty in /%ROOT%/contact.php on line 57

My questions are, what am I doing wrong in my attempt to pass on the uploaded file as an attachment? And, why does $path\_of\_uploaded\_file seem to be empty? Also, not everyone will be uploading files, so how could I allow the submit?