Our image upload form always returns the error message, "Invalid file. Please click the 'Back' button on your browser and try again." Here are the basics.

==HTML FORM==

<form enctype=="multipart/form-data" action="phpscript.php" method="post">
<input type="file" name="uploadedfile[]">
<input type="file" name="uploadedfile[]">
<input type="file" name="uploadedfile[]">
<input type="submit" value="Submit" />
</form>

==PHP SCRIPT==

<?php
if ((($_FILES["uploadedfile"]["type"] == "image/gif")
|| ($_FILES["uploadedfile"]["type"] == "image/jpeg")
|| ($_FILES["uploadedfile"]["type"] == "image/jpg")
|| ($_FILES["uploadedfile"]["type"] == "image/png")
|| ($_FILES["uploadedfile"]["type"] == "image/bmp")
|| ($_FILES["uploadedfile"]["type"] == "image/pjpeg"))
&& ($_FILES["uploadedfile"]["size"] < 20000))
  {
      move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],
      "http://mydomain.com/uploads/" . $_FILES["uploadedfile"]["name"]);
      $send = mail($to, $subject, $body, $headers);
      header( "Location: http://www.mydomain.com/" );
  } 
      else {echo "Invalid file. Please click the 'Back' button on your browser and try again.";}
?>

I've tried rearranging the upload form PHP, but if the form works at all it just sends us the rest of the form information in an email (which we want it to do) but the images never upload to the "uploads" folder. What's wrong?

Recommended Answers

Notice the "==" besides the enctype attribute.

I would also remove the brackets "[]" from the name.

Jump to Post

All 3 Replies

Notice the "==" besides the enctype attribute.

I would also remove the brackets "[]" from the name.

keith, thanks for the good eye regarding the "=="! I also changed the destination from "http://mydomain.com/uploads/" to basically "home/user/public_html/uploads/" and added bracketed numbers to the end of $_FILES. For example, $_FILES["uploadedfile"]["tmp_name"][0] and $_FILES["uploadedfile"]["tmp_name"][1].

Good.

I didn't even look at the php. Nice catch.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.