Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
We don't bite newbies here... much
 
PerlMonks  

Mime types.

by Punto (Scribe)
on Jun 18, 2000 at 06:12 UTC ( [id://18702]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

Punto has asked for the wisdom of the Perl Monks concerning the following question:

Hi.. I'm (still) writting a "free webmail" script, I'm using MIME::Entity to create the outgoing mail. To add attachments to the mail I have to use this code (taken from the documentation of the module):
$top->attach(Path => $gif_path, Type => "image/gif", Encoding => "base64");
Since the user is uploading the file, I don't know wich type to use.. Does it make any difference if I just use "image/gif", o something like "unknown/unknown" for everything?

Also, does anyone know if there is a way to provide a filehandle instead of a path to the file, to create the e-mail? (I'm getting the filehandle from cgi->upload(), so I'd have to create a file just to delete it after)

Thanks..

Replies are listed 'Best First'.
RE: Mime types.
by le (Friar) on Jun 18, 2000 at 08:31 UTC
    Also, does anyone know if there is a way to provide a filehandle instead of a path to the file...

    According to 'perldoc CGI':
    The filename returned is also a file handle. You can read the contents of the file using standard Perl file reading calls:
    # Read a text file and print it out while (<$filename>) { print; } # Copy a binary file to somewhere safe open (OUTFILE,">>/usr/local/web/users/feedback"); while ($bytesread=read($filename,$buffer,1024)) { print OUTFILE $buffer; }
    And you can get the MIME type, too.
    $filename = $query->param('uploaded_file'); $type = $query->uploadInfo($filename)->{'Content-Type'};
      >$type = $query->uploadInfo($filename)->{'Content-Type'};

      I get "Can't use an undefined value as a HASH reference" with that code.. Any idea what it is?

      Thanks..

        Maybe $filename is undef. Did you actually get a file?
Re: Mime types.
by mdillon (Priest) on Jun 18, 2000 at 16:02 UTC

    to figure out the correct MIME type for the file, you could use the File::MMagic module (there's no way i would use the MIME type sent in the client HTTP request, since many browsers these days seem to be horribly misconfigured w.r.t. MIME). i'm not sure how well it works under non-UNIX platforms, but it does have an 'external file' mode which i believe could be used under Windows with the /etc/magic file from a Linux distro, if necessary.

    if you can't figure out what the correct MIME type is, it is probably better to use application/octet-stream instead of unknown/unknown.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://18702]
Approved by root
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.