1

I have a form that sends a file, yet it's not being able to be called after submit.

Form:

<form class="form-inline" action="#" id="login" method="post">
<input type="file" name="file" id="file">
<input type="hidden" name="test" value="testy"> 
<input class="btn btn-primary btn-block" type="submit" name="submit" value="Go">
</form>

The value of testy comes up just fine, but nothing from _FILES after it's uploaded.

This was working when I was sending from one page to another page, but since I moved it all to happen on the same page, it's no longer working. What am I missing?

$_POST['test'] shows testy

$_FILES['file'] shows empty

1 Answer 1

4

You need enctype="multipart/form-data" attribute in your form:

<form class="form-inline" action="#" id="login" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file">
<input type="hidden" name="test" value="testy"> 
<input class="btn btn-primary btn-block" type="submit" name="submit" value="Go">
</form>
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you, I knew it was something stupid. Will this screw up any forms that don't contain a file upload (it's an optional field).
no, it should not be a problem for forms without file upload
Done, at the time it was too soon.
sorry, i was a bit rash
Silly StackOverflow and their 15 minute rule! :) thanks again

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.