PHP 4.2.2 and php://stdin

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am using php 4.2.2 in Red Hat 9.0 with apache 2.0.40 I try to build a
php script that accepts POST requests that contain multimedia data and
shoves them in a MySQL database. My problem is that it seems that I
cannot read the POST data from stdin.

I created the following php script to test it:


$in = fopen("php://stdin", "rb");
$line = fread($in, 10);
echo "Content-type: text/plain\n\n";
echo "len=".strlen($line)." OK\n";


and however I try to POST a file either with cURL (curl --data-binary
@file http://....) or with netcat (nc host port, ...) what I get back is

len=0 OK

i.e. no data are read!

Any ideas?

Re: PHP 4.2.2 and php://stdin

Stelios G. Sfakianakis wrote:

Quoted text here. Click to load it


$in = fopen("php://stdin", "rb");
I never saw such a way to receive a POST.
Where did you find it?

When somebody is submitting via a form some data, just receive it like this:

When you need to receive a file, which is send through a construct like  
<form enctype="multipart/form-data"  action="upload_process.php"  
 <input type="file" name="uploadthingy">
 <input type="submit" value="upload">

You receive the file in the script upload_process.php in a different way.

Read on here:

It is all pretty straightforward. Pay attention to read/write permissions in  
the used directories.

In case I completely misunderstood your question, which can easily be the  
case since I never saw that fopen("php://stdin", "rb"); construct before,  
forgive me. :-)

Erwin Moller

Re: PHP 4.2.2 and php://stdin

Erwin Moller wrote:
Quoted text here. Click to load it

I do not post through a form since the data are raw (e.g. an MPEG)
without being url encoded and so on. According to :

php://input allows you to read raw POST data. It is a less memory
intensive alternative to $HTTP_RAW_POST_DATA and does not need any
special php.ini directives. php://input is not available with

I am using the php://stdin because php://input is not available in php
4.2.2 but it seems that they are not equivalent.. On the other hand
$HTTP_RAW_POST_DATA requires AFAIK always_populate_post_data=On and it
seems to work with the "toy" script I gave but for some strange reason
it does not work with my full blown php script!!

I am really puzzled and frustrated!

Thank you anyway!

Quoted text here. Click to load it

Site Timeline