警告:file()[function.file]:文件名不能为空。 为什么?

When I am going to submit this (Warning: file() [function.file]: Filename cannot be empty) warning shows. How can I solve this problem. Please help I am new in php. Email has been sent but files doesn't attach. I want to sending mail with attach with raw php.

may code is look like this:

    $tmpName = $_FILES['attachment']['tmp_name'];
                    $fileType = $_FILES['attachment']['type'];
                    $fileName = $_FILES['attachment']['name'];

                    /* Start of headers */
                   $headers = "From: $fromName";

                  if (file($tmpName)) {
                  /* Reading file ('rb' = read binary)  */
                 $file = fopen($tmpName,'rb');
                 $data = fread($file,filesize($tmpName));
                 fclose($file);

                 /* a boundary string */
                $randomVal = md5(time());
                $mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";

                /* Header for File Attachment */
                  $headers .= "
MIME-Version: 1.0
";
                 $headers .= "Content-Type: multipart/mixed;
" ;
                 $headers .= " boundary=\"{$mimeBoundary}\"";

             /* Multipart Boundary above message */
             $message = "This is a multi-part message in MIME format.

" .
             "--{$mimeBoundary}
" .
            "Content-Type: text/plain; charset=\"iso-8859-1\"
" .
              "Content-Transfer-Encoding: 7bit

" .
               $message . "

";

             /* Encoding file data */
              $data = chunk_split(base64_encode($data));

             /* Adding attchment-file to message*/
             $message .= "--{$mimeBoundary}
" .
             "Content-Type: {$fileType};
" .
             " name=\"{$fileName}\"
" .
             "Content-Transfer-Encoding: base64

" .
             $data . "

" .
  "--{$mimeBoundary}--
";
}

 echo $message;
$sendmail = mail ("$to", "$subject", "$message", "$headers");

if($sendmail){
  echo "A email has been sent to: $to";
 }
else{
  echo "Error in Email sending";
}

}

if (file($tmpName)) {

You probably want if (file_exists($tmpName)) {?

Also make sure $tmpName is actually filled out.