0

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?

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by somedude3488
0

Notice the "==" besides the enctype attribute.

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

Edited by somedude3488: n/a

0

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].

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.