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

I need to transfer/extract the name value of a "form upload file field" .
I need a method so the <input type="file" size="10" name="shared_logo_filename"> field can pass the value to the next page like the text fields.
I did a search for "file upload" but none of the results addresses this issue. I am using CGI.pm, however it resides on a hosted server.

Initial file upload:
# upload some files? if (%$p_upload_files) { $err = &ui_Upload($p_upload_files); next Err if ($err); my $key = ''; foreach $key (keys %$p_upload_files) { my $p_hash = $$p_upload_files{$key}; next unless (($p_hash) and (defined($$p_hash{'serv +er file name'}))); $FORM{$key . "_filename"} = $$p_hash{'server file +name'}; delete $FORM{$key}; } } }

and for the text fields:
my %replace = (); $text = ''; my ($name, $value) = (); while (($name, $value) = each %FORM) { $replace{$name} = $value; next if ($name =~ m!^(shared|genesis_system)_!); next if (($name eq 'Action') or ($name eq 'Template') or ( +$name eq 'CWD') or ($name eq 'web_auth_cp')); $text .= &ue($name) . '=' . &ue($value) . "\n"; } &_load_system_values( \%replace, $FORM{'Template'} );

# save the name-value pairs that are specific to this template:
my $datafile = ".$FORM{'Template'}"; $datafile =~ s!/!.!g; $err = &WriteFile( $datafile, $text ); next Err if ($err);

This stores the information in the .shared.template for later retrieval so when a user opens a form
to make changes the information is still present in that particular form.
# save the name-value pairs that are specific to this template:

my $datafile = ".$FORM{'Template'}"; $datafile =~ s!/!.!g; $err = &WriteFile( $datafile, $text ); next Err if ($err);

# save the name-value pairs that are shared. This operation is a merge:
$datafile = '.shared.template'; my $shared = ''; if (-e $datafile) { ($err, $text) = &ReadFile($datafile); foreach (split(m!\n!, $text)) { next unless (m!^(.+)\=(.*)$!); next if (defined($FORM{"shared_$1"})); $shared .= "$_\n"; } } foreach (keys %FORM) { next unless (m!^shared_(.+)$!); $shared .= &ue($1) . '=' . &ue($FORM{$_}) . "\n"; } $err = &WriteFile($datafile, $shared); next Err if ($err);

Edited by planetscape - added (a few more) code tags

Edit: g0n - readmore tags

Replies are listed 'Best First'.
Re: Extract and Pass File Upload Value
by fmerges (Chaplain) on Apr 28, 2006 at 21:16 UTC

    Hi,

    IMHO, think about using sessions, for example CGI::Session. For uploaded files, you can save the file somewhere and store the path in the session. Take a look at FileUpload::Filename to use the same filename as the user gave to the file. You can use the session ID as the directory for storing uploaded files from a given user on the servers filesystem.

    Then once the user make the final commit, store it to the final destination, moving it from the temporary location to the final one...

    Regards,

    fmerges at irc.freenode.net
      I downloaded FileUpload-Filename-0.01 and read the MAN and came to the conclusion that I may not be able to utilize it. However, your advise did lead me to a perl module on CPAN named HTML Validation. With the prior, there are numerous pms required to download eg. Browser Detect... etc, however with the latter there are none.

      I tested the pm at http://www.htmlhelp.org/tools/validator/upload.html.en and it does just what I need it to do without the additional pms - returning the results to an assigned page.

      I already have a system in place where each users data is stored in ./shared.template in their individual directories. When a user fills out a particular form, that form along with the users input is copied to thier directory.

      I need a solution to write the file input value to "whatever.template" after the form is submitted, such as the above url example.

      I have downloaded and reviewed the source code for HTML:Validator, yet have not found a way to neither integrate it with my template.pm (primary code already submitted) nor extract filename as a stand-alone pm.

      If needed I can private message the url to my project.

      Thanks

        Hi,

        I don't understand what you wanna do. Could you explain in a high level what you want to do?

        Regards,

        fmerges at irc.freenode.net
Re: Extract and Pass File Upload Value
by stu42j (Sexton) on Apr 28, 2006 at 18:23 UTC
    Browsers won't let you specify a file upload the same way you can with a text field. You'll have to save the file on the server and keep a reference to it.