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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:00:24+00:00 2026-05-29T07:00:24+00:00

SOLVED! Used this example from php.net post method handling multiple uploads, with the knowledge

  • 0

SOLVED! Used this example from php.net post method handling multiple uploads, with the knowledge gained by using andre’s answer which is why I selected it as the answer, here it goes!

foreach ($_FILES["userfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
  if ($x=="0"){
    $data=explode(".",$_FILES["userfile"]["name"][$key]);
    $named=$id[id].".".$data[1];
    $x=$x+1;
    }else{
    $data=explode(".",$_FILES["userfile"]["name"][$key]);
    $named=$id[id]."-".$x.".".$data[1];
    $x=$x+1;
    }
    $uploaddir = '/home/content/92/8498392/html/items/'.$_POST[catid];
    $tmp_name = $_FILES["userfile"]["tmp_name"][$key];
    move_uploaded_file($tmp_name, "$uploaddir/$named");
}

}

The result is the first image is uploaded as 45.jpg, the second is uploaded as 45-1.jpg and so forth! Thanks for the help guys 😀

  • 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-29T07:00:24+00:00Added an answer on May 29, 2026 at 7:00 am

    The problem is how you are iterating over the $_FILES array. It does not handle mutliple files like you think so use the functions below and incorporate them into your script. The credit for the script below goes to the guy on the PHP site. Link is below the code.

    function multiple(array $_files, $top = TRUE)
    {
        $files = array();
        foreach($_files as $name=>$file){
            if($top) $sub_name = $file['name'];
            else    $sub_name = $name;
    
            if(is_array($sub_name)){
                foreach(array_keys($sub_name) as $key){
                    $files[$name][$key] = array(
                        'name'     => $file['name'][$key],
                        'type'     => $file['type'][$key],
                        'tmp_name' => $file['tmp_name'][$key],
                        'error'    => $file['error'][$key],
                        'size'     => $file['size'][$key],
                    );
                    $files[$name] = multiple($files[$name], FALSE);
                }
            }else{
                $files[$name] = $file;
            }
        }
        return $files;
    }
    
    print_r($_FILES);
    /*
    Array
    (
        [image] => Array
            (
                [name] => Array
                    (
                        [0] => 400.png
                    )
                [type] => Array
                    (
                        [0] => image/png
                    )
                [tmp_name] => Array
                    (
                        [0] => /tmp/php5Wx0aJ
                    )
                [error] => Array
                    (
                        [0] => 0
                    )
                [size] => Array
                    (
                        [0] => 15726
                    )
            )
    )
    */
    $files = multiple($_FILES);
    print_r($files);
    /*
    Array
    (
        [image] => Array
            (
                [0] => Array
                    (
                        [name] => 400.png
                        [type] => image/png
                        [tmp_name] => /tmp/php5Wx0aJ
                        [error] => 0
                        [size] => 15726
                    )
            )
    )
    */
    ?>
    

    I took this from the PHP website

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

Sidebar

Related Questions

I am currently working in PHP, so this example will be in PHP, but
From this example: http://datamapper.wanwizard.eu/pages/getadvanced.html#Deep.Relationship.Include You can see that it says: At this time, deep
@Solved The two subquestions I have created have been solved (yay for splitting this
SOLVED: This is what was wrong: current.addFolder(folder); (in the final else clause of the
I'm using the Facebook php-sdk to get the users name and friends, right now
I want to export the first image link from given text with PHP. Let's
I have a program i frequently use that is made with .NET. This program
I'm writing a C parser using PLY, and recently ran into a problem. This
I have been reading this paper titled Clone Detection using Abstract Syntax Trees by
I wrote a few custom workflow activities and from the browser i used several

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.