0

My PHP upload script is not getting anything from my form. Here is my form:

<small>Must be JPG, max 200kb</small>
<input id="image" type="checkbox" name="image" value="yes">
<input type="file" name="file" id="file">

Here is the section of PHP that handles the upload, I know that $image does infact = 'yes', so it looks like the problem is with the $_FILES array, as $_FILES["file"]["size"] is empty:

if ($image=="yes" && $_FILES["file"]["size"]>0) {
    if ((($_FILES["file"]["type"] == "image/jpeg")
        || ($_FILES["file"]["type"] == "image/pjpeg"))
        && ($_FILES["file"]["size"] < 200000))
          {
          if ($_FILES["file"]["error"] > 0)
            {
            $picstuff="Return Code: " . $_FILES["file"]["error"] . "<br />";
            }
          else
            {
            $picstuff= "Upload: " . $_FILES["file"]["name"] . "<br />
            Type: " . $_FILES["file"]["type"] . "<br />
            Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br /><br><br>
            <center>Please note it can take a couple of minutes for the image to be processed.</center><br><br>";

            move_uploaded_file($_FILES["file"]["tmp_name"], "images/$id.jpg");
            $query="UPDATE content SET image='yes' WHERE `id`='$id'";
            $result=mysql_query($query);
            }
          }
        else
          {
            $picstuff = "Image too large or incorrect format. Please upload a jpeg less than 200kb.";
            $image= "no";
            $query="UPDATE content SET image='No' WHERE `id`='$id'";
            $result=mysql_query($query);
          }
    } else
          {
            $picstuff = 'No File found';
            $image= "no";
            $query="UPDATE content SET image='No' WHERE `id`='$id'";
            $result=mysql_query($query);
          };

Every time I try upload I just get the 'No File found'. Would appreciate any help!

4
  • 3
    Did you have insert enctype="multipart/form-data" in your form? Commented Feb 5, 2015 at 21:14
  • Is your form multipart/form-data ? Commented Feb 5, 2015 at 21:15
  • no i don't, should i put that in my form tag? Commented Feb 5, 2015 at 21:16
  • You should. w3.org/TR/html401/interact/forms.html#h-17.13.4.2 Commented Feb 5, 2015 at 21:17

1 Answer 1

1

I put enctype="multipart/form-data" into my form tag and it fixed my problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.