user47823
user47823

Reputation: 49

PHP file upload not working

I'm trying to upload files to my server but it doesn't work at all. Here is test code:

<?php
echo count($_FILES['upload']['name']);
?>

<!DOCTYPE html>
<html>
<body>

<form action="" method="POST" enctype="multipart/form-data">
    <input name="upload[]" type="file" accept=".mp3" multiple="multiple" />
    <br>
    <input type="submit" value="Upload">
</form>

</body>
</html>

It always prints 0, file upload is enabled on my server.

Upvotes: 0

Views: 80

Answers (2)

user5957930
user5957930

Reputation:

The problem is that you're not counting the $_FILES['upload'].

Simple fix for your problem
Use:

echo count($_FILES['upload']);

Instead of:

echo count($_FILES['upload']['name']);

Edit: Remove [] from the input's name.

Upvotes: 1

Ash
Ash

Reputation: 17

  <?php
  echo count($_FILES['upload']);//only this modified//
  ?>

  <!DOCTYPE html>
  <html>
  <body>
       <form action="" method="POST" enctype="multipart/form-data">
            <input name="upload[]" type="file" accept=".mp3" multiple="multiple" />
            <br>
            <input type="submit" value="Upload">
  </form>

  </body>
  </html>

Upvotes: 0

Related Questions