Re: retrieve POST body?
| From: | Justin Frim | Date: | Fri, 20 Apr 2007 01:33:00 +0000 |
| Subject: | Re: retrieve POST body? | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-253309@lists.php.net to get a copy of this message | ||
Sorry burst your bubble, but your solution isn't a viable one in my case.
php://input only works if the form is submitted using application/x-www-form-urlencoded.
Take your sample HTML code there and add enctype="multipart/form-data" to the <form> tag, and I'm pretty sure you'll find that php://input contains no data. (Both PHP 5.2.1 running as a CGI on Windows and PHP 5.2.0 running as an Apache module on FreeBSD exhibit this behaviour.)
And before anyone asks, it *is* a requirement to accept multipart/form-data submissions because that's the only way you can properly implement a file upload on a web form.
Myron Turner wrote:
Tijnema ! wrote:On 4/19/07, Myron Turner <turnermm02@shaw.ca> wrote:php://stdin perhaps? On 4/18/07, Justin Frim <jfrim@idirect.com> wrote:André Medeiros wrote:Reading from php://input on a webserver will retrieve the BodyAndré Medeiros wrote:of theHTTP Request.Not for me it doesn't. That only seems to work when the form is submitted as application/x-www-form-urlencoded. When the form is submitted as multipart/form-data, php://input is blank.You're right. It doesn't carry across from Perl to PHP. As penance, I worked out how to do it using PHP: <form action = "post_data.php" method="post"> <input type= "hidden" value = "abcdefg" name="post_test"> <input type = "submit" name="submit" value="submit_this"> </form> <?php if(isset($_POST['submit'])) { $putdata = fopen("php://input", "r"); /* Read the data and write it to stdout */ while ($data = fread($putdata, 1024)) echo $data, "\n"; /* Close the streams */ fclose($fp); fclose($putdata); } ?>You probably could use this small Perl script via exec: #!/usr/bin/perl if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } print $buffer;If you call this script via exec, it can't return the POST data send to the PHP script right?btw, we are here on a PHP list, not PERL :)Does this mean you wouldn't use exec or system to run anything but PHP scripts? Or just that you wouldn't talk about it here, under penalty of exclusion from PHP heaven? :)