2

I have a simple HTML form containing a file input. When the form is submitted without a file, printing the $_POST array shows me all of the data submitted. When a file is submitted, however, $_POST doesn't print out any of the submitted data.

Can somebody tell me why? This is my code:

<?php
    print_r($_POST);
?>
<form action="test.php" method="post" enctype="multipart/form-data">
    <label for="myfile">Video File:</label>
    <input type="file" name="myfile" />
    <br /><br />
    <label for="mytitle">Title:</label><br />
    <input type="text" name="mytitle" size="55" maxlength="60" />
    <br /><br />
    <input type="submit" name="mysubmit" value="Submit Video for Approval" />
</form>
4
  • Depends on what function you're using to print the data... Try var_dump() Commented Jan 1, 2013 at 23:31
  • Why it depends? I haven't heard of this yet Commented Jan 1, 2013 at 23:32
  • @ArtaexMedia What? It's not a problem printing the data, it's the fact that the data isn't even there. echo $_POST['title']; gives me nothing either. Commented Jan 1, 2013 at 23:34
  • @DannyF247 could you be reaching post_max_size when you upload that file (that file being very close/over that limit)? This would be a very edge case and PHP should error out AFAIK anyway. Let me see if I understood clearly: you've entered something into mytitle and it didn't show up, did it? Commented Jan 1, 2013 at 23:38

2 Answers 2

4

Your script seems fine. Please check your server configuration. Perhaps you exceed POST limits (set with post_max_size in php.ini)

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

2 Comments

Silly me, you're right. My file was exceeding the max POST size, so I guess all my other data was truncated as well.
Yes, sorry I was going to earlier but it said to wait 10 more minutes, and I completely forgot about it. Thanks for the help!
2

You have to use $_FILES to access the uploaded files.

var_dump($_FILES); // Your uploaded files
var_dump($_POST);  // Your entered data

3 Comments

I understand I need to use $_FILES to access my file, but what about the other data in my form?
The other data should be in $_POST
You can still use $_POST with $_FILES together

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.