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 8939773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:53:37+00:00 2026-06-15T10:53:37+00:00

I have an HTML form that contains the following code: <input id=image_22 name=images[] type=file

  • 0

I have an HTML form that contains the following code:

<input id="image_22" name="images[]" type="file"  />
<input id="image_8" name="images[]" type="file"  />   

I’d like to be able to store the form input ID element in a variable (e.g. $imgnumber = ‘image_22’). Is this possible? See my comment in the code below:

PHP:

for ($i = 0; $i < count($_FILES['images']['name']); $i++) {
        $number_of_file_fields++;
        if ($_FILES['images']['name'][$i] != '') { //check if file field empty or not
            $number_of_uploaded_files++;
            $uploaded_files[] = $_FILES['images']['name'][$i];

            if (move_uploaded_file($_FILES['images']['tmp_name'][$i], $upload_directory . $_FILES['images']['name'][$i])) {

                $number_of_moved_files++;
                // *** COMMENT *** // 
                $imgnumber = CURRENT_FILE_INPUT_ID - this would store e.g. "image_22"
                }

            }

    }

Many thanks for any help with this 🙂

  • 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-06-15T10:53:38+00:00Added an answer on June 15, 2026 at 10:53 am

    Only the name and value of inputs are submitted to the server side. You could code the ID into the name instead of using an array of files.

    <input id="image_22" name="image_22" type="file"  />
    <input id="image_8" name="image_8" type="file"  />
    

    Access on the PHP side:

    foreach($_FILES as $imageName => $file)
    {
        // $imageName contains image_22 or image_8
        // $file contains the full array for this particular file
    }
    

    Edit:

    Your updated PHP code could be:

    foreach($_FILES as $imageName => $file)
    {
        $number_of_file_fields++;
        if ($file['name'] != '') { //check if file field empty or not
            $number_of_uploaded_files++;
            $uploaded_files[] = $file['name'];
    
            if (move_uploaded_file($file['tmp_name'], $upload_directory . $file['name'])) {
    
                $number_of_moved_files++;
                // *** COMMENT *** // 
                $imgnumber = $imageName; // image_22 or image_8
            }
        }
    }
    

    Failing that, you will have to send the ID as a separate variable, for example using a hidden input or the querystring.

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

Sidebar

Related Questions

In my HTML code, I have a form tag that contains two input boxes,
I have an HTML form that needs multiple submit buttons, like this: <input type=submit
I have a following problem, I have HTML form that uploads a file with
I have a simple html form that looks like the following <form action=search.php method=get>
I have the following code. def add_resume_link(name, form) link_to_function name do |page| html =
I have an asp.net form that contains some html, 2 controls a calendar from
I have a web site that contains an HTML form, in this form I
To dynamically fill DropDown controls on my HTML Form, I have written code that
I have a View that contains the following Line of code: //(DaysOfWeek is a
I have a search form that looks like this: The code behind the form

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.