Attaching file to Mail

Let me surmise the case first.
1. i am sending a file using <input type=file>
    method = post enc=multipart/form-data
   to a cgi prog which uses sendmail .

2. in the cgi prog i am using MIME::Entity
    developed by Zeegee software
The problem is that I can only attach a file which
is on the server. When working from a remote
machine I get an error saying
read-open "filename": No such file or directory at /usr/lib/perl5/site_perl/MIME/ line 407

obviously ,  the program cannot find the file.
Is the remote file not getting uploaded or am i
missing something ?
I have a skeleton code .
My code : -

use CGI qw/:standard :html3/;
use CGI::Carp qw/fatalsToBrowser set_message/;
use MIME::Entity;
print header();
print start_html (
                   -title => 'raj test mail',
print end_html();
    sub handler {
     $err = shift;
     print "<H1>Hmm.. Found an Error</h1>";
     print "<b>$err</b>";
MAIN  : {
  $query = new CGI;
  @var = $query->param();
  for $var (@var){
    ${$var} = $query->param($var);
  $top =build MIME::Entity From => $from,
                           To => $to,
                           Subject => $subj,
                           Data  => $message,
         or croak " Cannot build $top" ;
  if ( $file ){
     $top->attach( Path => $file,
                   Type => "text/html",
                   Encoding => "-SUGGEST"
 open( MAIL ,"| /usr/sbin/sendmail -t -oi") or croak "Cannot open MAIL program";
 close MAIL ;
   $subj = "unspecified";
<Body Bgcolor=white Text=black>
<Font Face='Verdana,Arial,Helvetica' Size=2>
<h1>The Mail to $to subject $subj has been sent</h1>
<b>Thank you for using raj mail</b>

<b>Thank you for using raj mail</b>

print end_html();  

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

When you upload a file to the web server, you need to have your CGI program read the data and save it on the system where it is running. I don't see any code in your script to do this.

Also, where is the $file variable being set? If you are assuming that the file being uploaded is automatically saved by the web server, your assumption is incorrect.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The perldoc for CGI indicates that $file is the
full path to the file on the user's machine, which
is true.  It indicates that this is also a filehandle that
you can use to directly access the file, however
that is not the case as $file is not on the local
machine.  There is a function in CGI called tmpFileName and you can use that function to get the path to the temporary file.

$tmp_file = tmpFileName($file);
open FILE, $tmp_file;
while (<FILE>) {
close FILE;

prakashk021799Commented: does not automatically initialize the variable $file with the name of the uploaded file. The documentation says:

       When the form is processed, you can retrieve the entered
       filename by calling param().

              $filename = $query->param('uploaded_file');

The above assumes that 'uploaded_file' is the value of the NAME attribute of the INPUT parameter used in the form. Something like:

<INPUT TYPE="file" NAME="uploaded_file" ....>

The part about the $filename also being a handle is correct. Therefore, you can do:

while (<$filename>) {
    # process data or write it somewhere else
raj_chandranAuthor Commented:
thanks prakash,
i corrected that assumption  after posting the question
and a  walk .
Now iam opening the file  uploaded and writing the
contents to a   public dir.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.