Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6102747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:39:02+00:00 2026-05-23T13:39:02+00:00

I am attempting to have a file upload page that allows for an arbitrary

  • 0

I am attempting to have a file upload page that allows for an arbitrary amount of file uploads. I found javascript code that successfully creates a new file input field in the form when one is clicked, however, any fields besides the one hardcoded in html are not being sent to my perl CGI script.

Javascript

    function fileFields() {
         var x = document.getElementById('fileUpload');
         x.onclick = function() {
                var i = parseFloat(this.lastChild.id)+1;
                input = document.createElement("input");
                input.setAttribute("type", "file");
                input.setAttribute("name", 'fileName_' + i);
                input.setAttribute("id", i);
                this.appendChild(input);
         }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  fileFields();
});

HTML Form

<form action="https://www.indiana.edu/~webdeviu/phil/submit.cgi" method="post" enctype="multipart/form-data">
<select name="property">
     <TMPL_LOOP NAME="PROPS">
          <option value="<TMPL_VAR NAME="user">"><TMPL_VAR NAME="user"></option>
     </TMPL_LOOP>
</select>
<br />
<a href="#" id="fileUpload"><input type="file" name="file_1" id="1" /></a>
<br />
<input type="submit" name="submit" value="Upload" />
</form>

Perl CGI, portion that looks for multiple files

my @files;

my $i = 1;
my $file = $query->param("file_" . $i);
while ($file) {
    push(@files, $file);
    $i = $i + 1;
    $file = $query->param("file_" . $i);
}
print $query->header( );
print scalar(@files); # prints 1 regardless of how many files I upload
exit;

I also put an escape in the while loop at one point to print out $file once it is changed to “file_2”, and it is null at that point.

What am I missing? any help is much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:39:02+00:00Added an answer on May 23, 2026 at 1:39 pm

    You’ve named the dynamic file fields incorrectly:

    input.setAttribute("name", 'fileName_' + i);

    That should be this according to your CGI:

    input.setAttribute("name", 'file_' + i);

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been unsuccesfully attempting to upload an encrypted file to an FTP server,
I am attempting to upload a file from my html page to my servlet
I have an XML file that I am attempting to display solely by adding
I have some code where I'm attempting to create a temporary file to be
I have an upload form that posts to a hidden iframe. I am attempting
I have a file containing perl-style regexs of the form /pattern/replace/ that I'm attempting
I'm attempting to mock some file operations. In the real object I have: StreamWriter
I have been attempting to have a object that I can use across multiple
I am attempting to have mechanize select a form from a page, but the
I have an editor I am attempting to emulate that has some very nice

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.