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

  • Home
  • SEARCH
  • 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 8016147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:27:46+00:00 2026-06-04T20:27:46+00:00

Hi I’m very new to web development but have a coding background. I’m trying

  • 0

Hi I’m very new to web development but have a coding background. I’m trying to create a very simple multiple file uploader for a form i’m creating however i cannot for the life of me get it to work. I followed a tutorial i found online and here is what i have so far. I am getting the hmm echo ha

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  dir="ltr">
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title></title>
</head>
<body>
<form method="post" action="upload.php" enctype="multipart/form-data">
  <input name="filesToUpload[]" id="filesToUpload" type="file" multiple="" onChange="makeFileList();" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
</form>
    <p>
        <strong>Files You Selected:</strong>
    </p>
    <ul id="fileList"><li>No Files Selected</li></ul>

    <script type="text/javascript">
        function makeFileList() {
            var input = document.getElementById("filesToUpload");
            var ul = document.getElementById("fileList");
            while (ul.hasChildNodes()) {
                ul.removeChild(ul.firstChild);
            }
            for (var i = 0; i < input.files.length; i++) {
                var li = document.createElement("li");
                li.innerHTML = input.files[i].name;
                ul.appendChild(li);
            }
            if(!ul.hasChildNodes()) {
                var li = document.createElement("li");
                li.innerHTML = 'No Files Selected';
                ul.appendChild(li);
            }
        }
    </script>
</body>
</html>

PHP

<?PHP
if(count($_FILES['uploads']['filesToUpload'])) {
  foreach ($_FILES['uploads']['filesToUpload'] as $file) {
    move_uploaded_file($file, "uploads/" . "sample.png" );
  }
}else{
echo "hmm";
}
?>

EDIT

Okay i updated the php file to this and originally had an echo in which echoed my files correctly however i can’t get the actual upload to happen now i just want to add the file to my upload directory which i’ve set permissions on already to be 777 with filezilla and want to keep the same name of the file

<?PHP
if(count($_FILES['filesToUpload']['name'])) {
  foreach ($_FILES['filesToUpload']['name'] as $file) {
    move_uploaded_file($file, "uploads/" . $file );
  }
}else{
}
?>

Thank you very much for the help so far!

  • 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-04T20:27:47+00:00Added an answer on June 4, 2026 at 8:27 pm

    Your code

        count($_FILES['uploads']['filesToUpload'])
    

    Will always return zero, as that element does not actually exist in the $_FILES array.

    It may be more helpful to “print_r()” your $_FILES array in the event of an error (in test only). Here is an example of the multi-file upload syntax.

        Array
        (
            [filesToUpload] => Array
                (
                    [name] => Array
                        (
                            [0] => test.txt
                            [1] => test - Copy.txt
                        )
    
                    [type] => Array
                        (
                            [0] => text/plain
                            [1] => text/plain
                        )
    
                    [tmp_name] => Array
                        (
                            [0] => C:\xampp\tmp\php3770.tmp
                            [1] => C:\xampp\tmp\php3771.tmp
                        )
    
                    [error] => Array
                        (
                            [0] => 0
                            [1] => 0
                        )
    
                    [size] => Array
                        (
                            [0] => 0
                            [1] => 0
                        )
    
                )
    
        )
    

    Using count($_FILES[‘filesToUpload’][‘name’]) should be the fix for your script.

    EDIT

    With your code

        if(count($_FILES['filesToUpload']['name'])) {
          foreach ($_FILES['filesToUpload']['name'] as $file) {
            move_uploaded_file($file, "uploads/" . $file );
          }
        }
    

    You are sending the name ([‘name’] (which is an array element) as $file), which doesn’t translate, as the move_uploaded_file() is looking for the tmpname (or filepath) of the uploaded file. You can change what you have to this.

        if(count($_FILES['filesToUpload']['name'])) {
          foreach ($_FILES['filesToUpload']['tmp_name'] as $ref => $fullfilename) {
            move_uploaded_file($fullfilename, "uploads/" . $_FILES['filesToUpload']['name'][$ref] );
          }
        }
    

    This will get you in the ballpark, but I have to mention, that there are much better ways of handling this. I will try and post a class I have for multi-file upload (or find one on Google) and link it to comment on this page. But the above, should get you (at a bare minimum) what you are looking for.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

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.