I think you may be slightly confused on the whole files thing. A file is simply a bunch of bytes stored in a accessible little package on a drive - there's no 'magic' involved. A 'text' file is just a file which (a) will generally only contain nice 'readable' ASCII characters (plus some line endings) and (b) *may* indicate that it contains this by having a 'txt' or 'asc' or somesuch extension.

When a browser uploads a file to your server as part of a form, it simply reads the local bytes, munges them all into an HTTP-friendly packet and sends off the whole lot. What CGI.pm does for you is split off those bytes, save them to a temporary file and then give you access to a filehandle - basically a way of reading the bytes back in from the temporary file and doing somewhere else with them - writing back out to a file of your choosing, parsing, dividing-by-the-number-you-first-thought-of...whatever.

In order to have some idea of what the file actually contains - whether it's bunch of bytes that make up a picture, or the aforementioned nice'n'readable text file, you either need to examine the also-supplied-by-CGI.pm MIME type for the file, which will tell you whether it's a gif, an mp3, a text file or whatever. Generally, one does this in order to have an idea of the extension to then give the filename - never trust user-supplied filenames :)

Hope this helps

Ben


In reply to Re: Re: Re: Re: Re: file uploading by benn
in thread file uploading by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.