Perl Programming- uploading files without use CGI;

Status
Not open for further replies.

Kireidayo

Seniorius Lurkius
12
Is there any way for Perl to handle a form type "file" and upload the file without using the query->upload() command after calling use CGI;? First of all, I don't like using use CGI for some reason.. I like to program all of the data processing techniques and form parsing functions. I know how to save the file in a directory so that it creates the file or something.. the problem is pulling the specified file from the user's computer. Thanks.
 

sittidae

Ars Centurion
325
Subscriptor
Of course there is a way to do it. CGI.pm is, after all, a perl module written entirely in perl (no XS code). You can look at the module and see how it is handled or you can read the httpd specifications. Of course you need to make sure you handle everything correctly.

Or you can not reinvent the wheel and use a module that has been debugged and used by 1000's of programmers.
 

petrov

Ars Tribunus Militum
2,714
not using an existing library is idiotic. Since I'm assuming you are not an idiot, this must be a toy program for your own personal edification. To do what you want in perl is going to look something like:
Code:
# open up a socket on the filehandle SOCK, read the perlipc manpage if 
# you can't do this

print SOCK "POST /path/on/hostname/to/script.cgi HTTP/1.0\r\n";
print SOCK "Foo-Header: data value\r\n";  # this is stuff like User-Agent
print SOCK "Content-Type: multipart/form-data\r\n";  # or application/x-www-form-urlencoded
print SOCK "\r\n";
print SOCK $formData;  # see the RFC for the proper format of this data

# close SOCK and shutdown connection
 
Status
Not open for further replies.