1

I have a HTML form as follows:

<form action="/AddFile" method="post">
    <input type="file" name="filedata"/>
    <input type="submit" value="Add File"/>
</form>

When I use it and submit a file called foo with content bar the POST request contains filedata=foo not filedata=bar as expected.

What am I doing wrong? How do I get the content of the file?

2 Answers 2

1

One you need to add enctype="multipart/form-data" to the form.

Two you need to get the files from $_FILES instead.

Three I think it's file_get_contents($_FILES['filedata']['tmp_name']); to get the file's contents.

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

Comments

0

Your markup lacks the attribute enctype="multipart/form-data", which is needed when a file field is present. See HTML 4.01 spec on form element.

Using multipart/form-data, the file contents get sent. The rest depends on your server-side handler.

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.