I'm currently coding two classes: HttpRequest and HttpResponse. I want to code my own HTTP classes.
I'm encountering an issue with a POST method using a form with enctype=multipart/form-data: I can't get the request contents.
After a long research and searchs, I've found I have to use file_get_contents("php://input")
to get the request content.
When I test it, I have an empty string var_dump(file_get_contents("php://input"))
.
I have no access to server/php configuration.
I'm testing with the following code :
<?php
$input = file_get_contents('php://input');
var_dump($input);
?>
<html>
<body>
<form action="./" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="text" name="namen" id="nameid" /><br/>
<input type="file" name="file" id="file"><br>
<input type="file" name="file2" id="file2"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
And after submitting, I have this result : string(0) ""
.
It's obvious because php://input doesn't work with enctype=”multipart/form-data” forms.
I'd like to have something like :
-----------------------------19972703421793859182225487886
Content-Disposition: form-data; name="namen"
ds
-----------------------------19972703421793859182225487886
Content-Disposition: form-data; name="file"; filename="toto.xml"
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<Toto></Toto>
-----------------------------19972703421793859182225487886
Content-Disposition: form-data; name="file2"; filename=""
Content-Type: application/octet-stream
-----------------------------19972703421793859182225487886
Content-Disposition: form-data; name="submit"
Submit
-----------------------------19972703421793859182225487886--
Is a way it works for any request method ? Or am I wrong ?