ultranerds has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

This may help to read first:

[http://digitarald.de/forums/topic.php?id=2038&replies=1#post-2949]

This system uses MooTools http://mootools.net/

It works - but I'm trying to convert it to a Perl script (from a PHP one) ... and I'm struggling :(

In their example code, they say this works:

$main::cgi->param('Filedata')

..but its blank.

I also tried all of these:

print STDERR "File name: " . $cgi->param('Filename') . "\n"; print STDERR "Filedate: "; print STDERR "FOO 1" . $cgi->param('Filedata') . "\n";; print STDERR "FOO 1" . $main::cgi->param('Filedata') . "\n";


Has anyone got any ideas? I've been waiting for a week for a reply on their forum now, so I'm not holding up much hope of a reply from them :(

TIA

Andy

Replies are listed 'Best First'.
Re: MooTools - how to grab file contents?
by Corion (Patriarch) on Sep 14, 2010 at 08:10 UTC

    I guess it would help us what the "remote side" is sending. Most likely, if it is some fancy uploading thing, you can fake that by using a plain HTML page that does the file upload instead, or by using wget or curl to send the file upload data.

    It might also help to read the documentation of CGI, especially about file uploads. According to it, $cgi->param('Filename') will be both, a filehandle to the uploaded data as it has arrived and the filename. But you haven't told us (or the developers at that other forum) what you're doing.

    As with any Ajax site, please get it to work without Javascript first before trying to add Javascript to the problem.

      Hi,

      Yeah, I've tried it with this too:

      my $fh = $cgi->param('File name'); while (<$fh>) { print $_ }


      ..but that again prints out nothing

      Will have another play around with it later today, to see if I can get it working (and will try as you suggested, with a simple HTML form, without the JS code)

      Cheers

      Andy
        Maybe
        use Data::Dumper; print Dumper $cgi;
        might reveal something useful?
Re: MooTools - how to grab file contents?
by Proclus (Beadle) on Sep 15, 2010 at 17:57 UTC
    This is how I make it work with iPhone & Flash based binary uploads:
    Inside the loop you can detect which parameter is actually the name of the upload handle.
    my @params = $query->param; foreach my $param (@params) { my $upload_filehandle = $query->upload($param) +; if(defined($upload_filehandle)) { open UPLOADFILE, ">somePicture.jpg"; binmode UPLOADFILE; while( <$upload_filehandle>) { print UPLOADFILE; } close UPLOADFILE; } }
    You should add more validations and logic.