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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:53:41+00:00 2026-05-12T10:53:41+00:00

At work I’ve been dealing with some complex forms (publish pages of Symphony )

  • 0

At work I’ve been dealing with some complex forms (publish pages of Symphony) that contain multiple image upload fields. I need a way to quickly merge $_FILES with $_POST, unfortunately you cannot simply merge the two with array_merge because they don’t follow the same structure.

Basically if you have $_POST[a][b] it would be $_FILES[a][*][b]. Replace * with one of name, type, tmp_name, error or size.

The content of the $_FILES array as standard:

array
  'image-a' => array
      'name' => string '' (length=0)
      'type' => string '' (length=0)
      'tmp_name' => string '' (length=0)
      'error' => int 4
      'size' => int 0
  'image-b' => array
      'name' => string '' (length=0)
      'type' => string '' (length=0)
      'tmp_name' => string '' (length=0)
      'error' => int 4
      'size' => int 0
  'image' => array
      'name' => array
          'sub' => array
              'c' => string '' (length=0)
      'type' => array
          'sub' => array
              'c' => string '' (length=0)
      'tmp_name' => array
          'sub' => array
              'c' => string '' (length=0)
      'error' => array
          'sub' => array
              'c' => int 4
      'size' => array
          'sub' => array
              'c' => int 0

And the desired array after merging with $_POST:

array
  'MAX_FILE_SIZE' => string '5242880' (length=7)
  'image-a' => array
      'name' => string '' (length=0)
      'type' => string '' (length=0)
      'tmp_name' => string '' (length=0)
      'error' => int 4
      'size' => int 0
  'image-b' => array
      'name' => string '' (length=0)
      'type' => string '' (length=0)
      'tmp_name' => string '' (length=0)
      'error' => int 4
      'size' => int 0
  'image' => array
      'sub' => array
          'c' => array
              'name' => string '' (length=0)
              'type' => string '' (length=0)
              'tmp_name' => string '' (length=0)
              'error' => int 4
              'size' => int 0
  • 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-12T10:53:41+00:00Added an answer on May 12, 2026 at 10:53 am

    This is the solution I came up with, calling get_file_post_data returns the merged array:

    <?php
    
        if (!empty($_POST)) {
            header('content-type: text/plain');
    
            function merge_file_post_data($type, $file, &$post) {
                foreach ($file as $key => $value) {
                    if (!isset($post[$key])) $post[$key] = array();
                    if (is_array($value)) merge_file_post_data($type, $value, $post[$key]);
                    else $post[$key][$type] = $value;
                }
            }
    
            function get_file_post_data() {
                $files = array(
                    'name'        => array(),
                    'type'        => array(),
                    'tmp_name'    => array(),
                    'error'        => array(),
                    'size'        => array()
                );
                $post = $_POST;
    
                // Flip the first level with the second:
                foreach ($_FILES as $key_a => $data_a) {
                    foreach ($data_a as $key_b => $data_b) {
                        $files[$key_b][$key_a] = $data_b;
                    }
                }
    
                // Merge and make the first level the deepest level:
                foreach ($files as $type => $data) {
                    merge_file_post_data($type, $data, $post);
                }
    
                return $post;
            }
    
            var_dump(get_file_post_data());
        }
    
        else echo '
            <form action="" method="post" enctype="multipart/form-data">
                <input name="MAX_FILE_SIZE" type="hidden" value="5242880">
                <div><label class="file">Image A <input name="image-a" type="file"></label></div>
                <div><label class="file">Image B <input name="image-b" type="file"></label></div>
                <div><label class="file">Image C <input name="image[sub][c]" type="file"></label></div>
                <div><button type="submit">Send</button></div>
            </form>
        ';
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We work with some very large databases (300Gb - 1Tb). Tables can contain from
work on asp.net vs 05 C#.Master page header contain the bellow code <script type=text/javascript
I work with a client that is using purchase orders, and a custom order's
I work directly on a remote (S)FTP Server some times. I use textmate as
I work on a lot of ColdFusion projects that are housed on a single
I work on a large Java based web application, it has been built up
I work in an environment that is totally .NET. However, over the past few
I work with an e-commerce website that uses a PayPal checkout component written in
At work it is requested that I make a program that can broadcast a
At work, I have a large table (some 3 million rows, like 40-50 columns).

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.