Forum Moderators: coopster & phranque

Message Too Old, No Replies

form based file upload. How do I retrieve the file?

         

coolvirus

2:58 pm on Feb 20, 2002 (gmt 0)



When retrieving data from an HTML form, you can do it in 2 manners:
1. By reading from standard input if the form method is POST.
2. By reading from the environment variable QUERY_STRING if the form method is GET.
I'm successfully reading data from a form with any kind of input fields except when the input type=file. When I try to upload a file, I don't see anything coming in anywhere.

I know that the form enctype has to be set to "multipart/form-data". But where do I read any info pertaining to the file that is being uploaded by the user?
Is there an environment variable that contains the name and path of the file being uploaded?
I think I have to copy this file to a directory on the webserver but how can I copy it if I don't even know what the name of file is?
There is nothing in standard input or the QUERY_STRING variable so at this point, I don't know where else to look.

Any help will be deeply appreciated.

circuitjump

3:52 pm on Feb 20, 2002 (gmt 0)

10+ Year Member



What language are you using? (ASP, Perl, PHP ...)

coolvirus

4:06 pm on Feb 20, 2002 (gmt 0)



I'm using C on the server side.
I was looking at the Perl CGI.pm module which performs this task for you but since I don't know much Perl, I get lost reading it and have no idea how it extracts the uploaded file.

FYI, we are using Netscape server.

Brett_Tabke

4:34 pm on Feb 20, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



It comes in on standard input:

Here is a fairly good Perl explanation:
[vivtek.com...]

coolvirus

1:18 pm on Feb 22, 2002 (gmt 0)



I finally figured it out.
For those of you that know C, I was using fgets to read from standard input but for some reason, I wasn't getting anything. Then I found a sample program on the web that was using fread and once I switch to that, it worked.

Now comes the fun part...the parsing of the string when a file comes in. I don't think I'll need to save the file to the local drive so I'll try to parse through the contents of the uploaded file and do what I need to do with that data.

Thank you all for your help.

gethan

1:28 pm on Feb 22, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For the sake of completeness .. (I know your using C ;))

With perl and CGI.pm you get a filehandle object, in the name you gave the file in the form.

eg. my $fh = $cgi->param('file');

Now it can be copied;

use File::Copy cp;
cp ($fh,$newfilename);

etc.