help me to get pusr

Discussion in 'Perl' started by sasidv, Oct 31, 2011.

  1. sasidv

    sasidv New Member

    Joined:
    Oct 31, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    function setval()
    {
    var url = window.location.toString();
    url.match(/\?(.+)$/);
    var params = RegExp.$1;
    var params = params.split("&");
    var queryStringList = {};
    for(var i=0;i<params.length;i++)
    {
    var tmp = params[i].split("=");
    var acc_usr=tmp[1];
    document.getElementById('pusr').value = acc_usr;
    }
    }
     
    <body onload = "setval();">
    <FORM ENCTYPE="multipart/form-data" ACTION="/cgibin/fupload.cgi" METHOD="POST">
    <TABLE BORDER=0 WIDTH="550">
    <TR> <TD ALIGN=RIGHT>
    File Name:
    </TD>
    <TD>
    <INPUT TYPE="File" NAME="filetoupload01" SIZE="70">
    </TD> </TR>
    <TR> <TD COLSPAN=2>&nbsp;<BR></TD>
    </TR>
    <TR> <TD ALIGN=RIGHT>
    <INPUT TYPE="Submit" onclick="ValidateFilename(filetoupload01.value)" VALUE="UPLOAD FILE">
    <INPUT TYPE="HIDDEN" NAME="filetoupload02" VALUE="">
    </TD> <TD ALIGN=RIGHT >
    <INPUT TYPE="RESET" VALUE="RESET FORM">
    <INPUT TYPE="hidden" name="pusr" value="" />
    </TD>
    </TR>
    </TABLE>
    </FORM>
    </body>
    
    the following is the code in fupload.cgi

    Code:
    my %ufiles;
    foreach $key (sort {$a <=> $b} $query->param()) {
    next if ($key =~ /^\s*$/);
    next if ($query->param($key) =~ /^\s*$/);
    next if ($key !~ /^filetoupload_(\d+)$/);
    $Number = $1;
    if ($query->param($key) =~ /([^\/\\]+)$/) {
    $Filename = $1;
    $Filename =~ s/^\.+//;
    $ufiles{$Number} = $Filename;
    $File_Handle = $query->param($key);
    
    i want to read the value of <code>pusr</code> thats coming from the html form and rename the uploaded file with the name of pusr value
     
  2. chorny

    chorny New Member

    Joined:
    Jun 6, 2010
    Messages:
    20
    Likes Received:
    2
    Trophy Points:
    0
    Home Page:
    http://chorny.net
    use $handle file handle, you don't need value $query->param($key):

    Code:
        if (not($query->upload($key))) {
          if ($query->cgi_error) {
            die "Error uploading picture ".$query->cgi_error."\n";
          }
        } else {
          my $handle=$query->upload($key)->handle;
          ...
    
     
  3. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    48
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Code:
    use strict;
    use warnings;
    use CGI;
    
    my $cgi = new CGI;
    
    ## get all upload file input names
    my @all_upload_files = grep { /^filetoupload_(\d+)$/ } keys $cgi->Vars;
    
    foreach my $file_upload_name (@all_upload_files) {
        my ($filename) = $cgi->param($file_upload_name) =~ /([^\/\\]+)$/;
        ## append to filename/ or do whatever you want
        $filename .= '_' . $cgi->param('pusr');
    
        my $uph = $cgi->upload($file_upload_name);
        binmode $uph;
        open my $h, '>', "$filename" or die $!;
        while (<$uph>) {
            print {$h} $_;
        }
        close $h;
    
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice