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

I want to use an HTML form to process all files in a user defined directory. I don't want the users to have to enter the path in a textbox. Browsing to the directory seems to be the ideal method - and I can accomplish this using something similar to a file upload form:
$query = new CGI; if ($file = $query->param('filename')) {&parsefile} print $query->start_multipart_form; print $query->filefield('filename','',25), "  "; print $query->reset('Clear','reset'),$query->submit('submit','OK'); print $query->endform;
I haven't tried it, but since the variable $file contains the full path to the file, I imagine I could upload and process more than just the file selected by the user. This is not pretty, however. Is there a better way to do this?

Replies are listed 'Best First'.
Re: browse to directory
by rob_au (Abbot) on May 17, 2002 at 10:39 UTC
    In short, no, you cannot do this.

    This is because of the manner of interaction between the client and server - The submitted form information contains more than just the file name and path, but rather the entire file in encoded multipart format. The client does not submit the file name for the server to subsequently retrieve the file from the client, but rather the file name and path are secondary to the content of the request containing the encoded file. Multiple files can be uploaded with a single request, but there is no automatic method by which the server can expand upon a file path and retrieve files from the user machine - If this were possible, one could imagine the security problems that this could represent.

     

      Yes, I do see the security issues. We have tens of thousands of xml files to process, however, and I was hoping to use a better method than running a local script on these files, or forcing people to upload each one by one. I suppose I can archive the files into one file and upload this, then unarchive it and process them. Thanks for the help :)