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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:44:53+00:00 2026-05-17T14:44:53+00:00

I have a script I’m working out to upload up to 10 files at

  • 0

I have a script I’m working out to upload up to 10 files at once. I have 10 seperate inputs in my html:

  <?php
    for($i=0;$i<10;++$i) {
         $num = $i+1;
         echo '
            <span>'.$num.'</span><input type="file" name="photo'.$i.'" />
              ';
     }
  ?>

And then I have my uploader which I have used before–in a slightly different form–but can’t get to work now:

$path = "../path/to/folder/";
for($i = 0; $i < 20; $i++){
  $fileName = "photo". "$i";
  $filePath = "$path". "photo$i.jpg";

  if (!empty($_FILES['$fileName']['tmp_name'][$i])) {
       if (!copy($_FILES['$fileName']['tmp_name'][$i], $filePath)) {
            echo "failed to save '.$filePath.'";
        }
       chmod($filePath, 0644);
     }
 }

In a working version of this script I cut the for loop and just numbered each upload individually (I had this piece of code without the loop 10 times each with its own number). That worked great but it’s really pretty ugly to look at a piece of code like that. Any ideas how to make this work?

UPDATED:

Still not having any luck I appreciate all the help. I think my problem lies in that the $_FILES arrays aren’t being populated properly edits as follows:

changed HTML to:

  <?php
    for($i=0;$i<10;++$i) {
         $num = $i+1;
         echo '
            <span>'.$num.'</span><input type="file" name="photo[]" />
              ';
     }
  ?>

and the uploader script to:

$path = "../path/to/folder/";
for($i = 0; $i < 20; $i++){
  $fileName = "photo". "$i";
  $filePath = "$path$fileName.jpg";

  if (!empty($_FILES["photo"]["tmp_name"][$i])) {
       if (!copy($_FILES["photo"]["tmp_name"][$i], $filePath)) {
            echo "failed to save '.$filePath.'";
        }
       chmod($filePath, 0644);
     }
 }
  • 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-17T14:44:53+00:00Added an answer on May 17, 2026 at 2:44 pm

    You are using $i twice:

    $_FILES["$fileName"]["tmp_name"][$i]
    

    the [$i] part makes no sense to me: You are already accessing each element through $fileName. I think you need to simply get rid of [$i].

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

Sidebar

Related Questions

I have script called Script.php and tests for it in Tests/Script.php, but when I
I have script with defined class (for instance, Singleton.php). This class implements classic singleton
i have script <?php $to = $_GET[to]; header(Location: $to); ?> if i call script
i have script like this <html xmlns=http://www.w3.org/1999/xhtml> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8 /> <title>Testing
We have script http://site.com/ourscript.php How to add something like enter password block on that
I have ./script test\42 Here is an example script : #!/bin/sh echo $1 It
I have script that loops through an array of html tag id's, some elements
I have a question. In my file content.html I have script. When load this
i have script like this.... <head> <meta http-equiv=content-type content=text/html; charset=iso-8859-1 /> <meta name=author content=bbbbb
anyone have script or procedures to install SQL Server 2008 Express, set up the

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.