Search code examples
htmlmacosformsfirefoxenctype

Why isn't my form being submitted?


I've got a simple HTML form, thus:

<html>
<head></head>
<body>
    <form action="upload_file.php" method="post" enctype="multipart/form-data">
      <input name="filesToUpload" id="filesToUpload" type="file" />
      <input type="submit" value="Upload File" />
    </form>
</body>
</html>

When the user clicks submit, I expect to see the result come back via the upload_file.php script. But on FF 4.01 on the mac, absolutely nothing happens. The URL in the address bar stays the same, and my php script doesn't get called on the server. I can get it to submit the form if I change the enctype to something other than "multipart/form-data", or if I change the method from "post".

I'm at a loss to work out what's going on. Is it a FF / Mac bug, or something schtoopid I'm doing.

FWIW, here's the PHP script. It's stolen almost verbatim from the W3schools PHP upload tutorial:

<?php
if ($_FILES["filesToUpload"]["error"] > 0)
  {
  echo "Error: " . $_FILES["filesToUpload"]["error"] . "<br />";
  }
else
  {
  echo "Upload: " . $_FILES["filesToUpload"]["name"] . "<br />";
  echo "Type: " . $_FILES["filesToUpload"]["type"] . "<br />";
  echo "Size: " . ($_FILES["filesToUpload"]["size"] / 1024) . " Kb<br />";
  }
?> 

Solution

  • Oh, ok I seem to have worked it out. I had created a few dummy files to test the script I was going to use to check file name validity. But I created them just by going to the terminal and doing

    touch testfile.txt testfile2.txt testfile3.txt
    

    so the files were all zero bytes. This, it seems doesn't work for FF on the mac. It does for chrome however. On the PC I was choosing real files because I don't know the windows equivalent of the touch command, so that's why Firefox worked there.