Reputation: 68618
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?
Upvotes: 1
Views: 6180
Reputation: 201548
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.
Upvotes: 0
Reputation: 1732
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.
Upvotes: 1