in reply to HTML Form and Perl

I think what hasn't been mentioned so far is that the form doesn't have the elements that would make the browser actually upload the zipfile.  Maybe I'm misunderstanding things completely... but I thought I'd mention it — just in case... :)

How is the file supposed to be transferred to the server? You say in your PHP code

echo " This program uploads a zip file via ftp to a server <br>";

Is that "ftp" to be taken literally? If so, what/who is performing the FTP transfer? Is this being done separately (manually) before the form is submitted? Or is the file meant to be uploaded via the browser / HTTP upon submitting the form?

In case of the latter, there would normally need to be an <input type="file" ... >, together with the enctype="multipart/form-data" within the <form> tag.  In other words, as it is at the moment, one problem might be that nothing is really being uploaded, which would also explain why the unzipping doesn't work yet...

Replies are listed 'Best First'.
Re^2: HTML Form and Perl
by Anonymous Monk on May 08, 2008 at 22:42 UTC
    well i was writing the code in parts. So i just manually uploaded the zip file...to the server...just so i could test out that the unzip was working fine. Once i got that ok...i would add the file transfer. This is so basic a need (move a file to server and unzip it in a specified folder), i thought that it was well covered ground...but so far...no one has a solution that works that i have seen. BUT it is nice to know that i am not as stupid as i thought...or it would have been easy to do. :) Thanks for the interest and suggestions.
      i was writing the code in parts ...

      That's fine. Actually, it's a good strategy in general. I just wasn't sure what exactly you were expecting to happen... so I mentioned it...

      This is so basic a need (move a file to server and unzip it in a specified folder), i thought that it was well covered ground.

      Yes... in fact, it shouldn't be too hard. And I think you're pretty close to having it working.  What seems to be the problem with your last attempt is that that untainting regular expression in

      die "invalid dir" unless ($dir =~ m/^([a-zA-Z0-9]+)\z/);

      is missing a slash in its character set [a-zA-Z0-9] — note you're validating a path. Maybe, you'll also want to add stuff like underscore, dash, etc.  I.e. something like

      die "invalid dir" unless ($dir =~ m/^([\/\w-]+)\z/);

      (\w is short for "alphanumeric", i.e. alphabetic character, digit and underscore)

      As you had it, your CGI script was most likely dying with an "invalid dir" message written to stderr, in case you had specified a path like /frog/dog/cat. So, nothing after that line in the script did execute... By default, the message would end up in the webserver's error log, but you change that by adding

      use CGI::Carp 'fatalsToBrowser';

      somewhere near the top of the CGI script. This would redirect fatal error messages to the browser, which is nice for debugging purposes (you might want to disable it again, once things are working...).  Good luck.