in reply to Re: Re: file uploading
in thread file uploading
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: file uploading
by Anonymous Monk on Apr 15, 2003 at 17:59 UTC | |
| [reply] [d/l] |
by chromatic (Archbishop) on Apr 15, 2003 at 18:39 UTC | |
May I suggest trying the documentation again? CGI.pm is exceedingly well documented. The examples you copied are highly incorrect. In particular:
Calling binmode on a string doesn't do anything useful -- it only does something interesting on filehandles.
Attempting to read from a string doesn't do anything useful -- it's a symbolic reference, but since you don't open a filehandle anywhere called 'text.txt', you won't get any data.
Again, $filename isn't a filehandle or even a symbolic reference to a filehandle. Even if it were, you'd have read everything from it in the while loop above. Besides that, mixing buffered reads with unbuffered generally mixes things up. The CGI documentation is *really* good about explaining how to receive uploaded files. It's well-worth your time to figure out how to read it rather than trying to copy and paste several other scripts together. That's obviously not working here. Why not try something different? | [reply] [d/l] [select] |
by benn (Vicar) on Apr 15, 2003 at 22:21 UTC | |
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 | [reply] |