in reply to Upload file- Ajax+Perl

Hi

for ajax file upload : keep in mind that you can get your file by reading STDIN ( without calling CGI , don't include it ). Send the other informations as HTTP headers.

my $fn = (exists $ENV{'HTTP_X_FILENAME'} ? $ENV{'HTTP_X_FILENAME'} + : "" ); my $rep = (exists $ENV{'HTTP_X_REP'} ? $ENV{'HTTP_X_REP'} : "" ); print "Content-type: text/html; charset=utf-8\r\n\r\n" ; my $repTmp = "/tmp/" ; my $fichier = "$repTmp/$fn" ; my $len = 0 ; if( open ( UPLOADFILE, ">$fichier" ) ) { binmode UPLOADFILE; while( <STDIN> ) { print UPLOADFILE $_ ; $len += length($_); } close UPLOADFILE ; } # an internal function to verify the file and to move it fais_copy($repTmp , $fn,$rep,1,0); print "ok $rep$fn de $len octets\n" ;

For multiple files, an AJAX post makes several calls to the same cgi. Then it is ok.

I made this tiny script to handle the filedrag.js by Craig Buckler (@craigbuckler) of OptimalWorks.net instead using php

Igael

Replies are listed 'Best First'.
Re^2: Upload file- Ajax+Perl
by Anonymous Monk on Jan 30, 2014 at 00:01 UTC

    for ajax file upload : keep in mind that you can get your file by reading STDIN

    You can also make a nice hat by stabbing yourself with a knife, doesn't make it a good idea

Re^2: Upload file- Ajax+Perl
by Anonymous Monk on Jul 10, 2016 at 15:14 UTC
    Finally, this worked for me. But why CGI is not used here? Does that mean I need to send all the other data via http headers, for example if I send a form with multiple fields and files?

      Finally, this worked for me. But why CGI is not used here?

      Because the guy who wrote it is naive/ignorant.

      Does that mean I need to send all the other data via http headers, for example if I send a form with multiple fields and files?

      No. If your server program is running under CGI use CGI module for getting at the data.

        Right, the body of the request can be accessed via CGI. I used $cgi->param('POSTDATA') to save the uploaded file.