in reply to Re: Re: Re: Re: file uploading
in thread file uploading

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