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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:14:05+00:00 2026-05-12T16:14:05+00:00

I have a foreach loop that is suppose to check to see if a

  • 0

I have a foreach loop that is suppose to check to see if a checkbox is checked by an item. If the checkbox is checked I need to see if the file upload part of the script has a value and if so then proceed to check the file type and size of the file the user is trying to upload.

Currently if there is only an error with the first checkbox then this works fine but for some reason if there is an error with more than one file it will loop the results again. For example if there is an error with two files it will give four results (listing each error twice) if an error with three items I get 6 results.

I’m really new to loops and am wondering if I should switch to a for loop and do something like loop until errors equal zero.

Here is my html

<ul class="imgPreview">
    <li>
        <a href="#">dialogwarning_pimg4_15_1276648623.png</a> 
        <a href="#" class="edit_project_file"> <img src="images/edit.gif"/></a>
    </li>
    <li>
        <input name="upload_project_images[]" type="file" /> 
    </li>
    <li>
        <input name="edit_image[]" type="checkbox" value="dialogwarning_pimg4_15_1276648623.png"/>
    </li>
    <li>
        <a href="#">formatjustifyright_pimg3_15_1276648623.png</a>
    </li>
    <li class="edit_project_image">
        <input name="upload_project_images[]" type="file" />
    </li>
        <li class ="edit_file_checkbox">
        <input name="edit_image[]" type="checkbox" value="formatjustifyright_pimg3_15_1276648623.png"/>
    </li>
</ul>

The PHP for loop is as followed:

$remove_images_files = $_POST['edit_image'];    

if(isset($remove_images_files)){
    foreach ($remove_images_files as $update){
        foreach ($_FILES["upload_project_images"]["type"] as $key => $type) {
        $upload_project_images = $_FILES["upload_project_images"]["name"][$key];
        $upload_project_images_type = $_FILES["upload_project_images"]["type"][$key];
        $upload_project_images_size = $_FILES["upload_project_images"]["size"][$key];
        $upload_project_image_ext = strtolower(substr($upload_project_images, strrpos($upload_project_images, '.') + 1));
            if($upload_project_images != "") {
                if((!in_array($upload_project_images_type,$upload_permitted_types['mime'])) || (!in_array($upload_project_image_ext,$upload_permitted_types['ext']))) {
                    $errmsg_arr[] = 'Please select a jpg, jpeg, gif, or png image to use as the project image' .$upload_project_images . $upload_project_image_ext;
                    $errflag = true;
                }
                elseif($upload_project_images_size > $max_upload_size_bytes ) {
                    $errmsg_arr[] = 'Please select an image smaller than '. $max_upload_size_Kbytes .' to use as the project image';
                    $errflag = true;
                }
            }
        }
    }
}
  • 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-12T16:14:05+00:00Added an answer on May 12, 2026 at 4:14 pm

    Your problem may be that you are iterating over

    $_FILES["upload_project_images"]["type"]
    

    for every entry in $remove_images_files, which I don’t think is what you want to do. If you take out the following line:

    foreach ($remove_images_files as $update){
    

    and its corresponding }, does it do what you want it to do?

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

Sidebar

Related Questions

Right now I have a foreach loop that grabs the first link with an
in a ASP.NET application (MVC) I have a foreach loop that loops through a
I have a simple Parallel.Foreach loop that has about 1000 rows in the DataTable,
In PHP I can use a foreach loop such that I have access to
I have a loop that enters each non-empty text field into a database: foreach
I have a datatable that I add to the chart in foreach loop as
I have a foreach loop in jQuery going through each 'div.panel', I need to
I have a foreach loop that starts a process within a try/catch. In the
in my asp.net mark up I have a foreach loop that iterates through a
Suppose I have some code that looks like this: foreach(type x in list y)

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.