473,225 Members | 958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

PHP 4.2.2 and php://stdin

Hello,
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:

<?php

$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?
Thanks!
Sep 8 '05 #1
2 7389
Stelios G. Sfakianakis wrote:
Hello,
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:

<?php

$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?
Thanks!


Hi,

$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:
$_POST["name"];

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

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

Read on here: http://nl2.php.net/features.file-upload

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. :-)

Regards,
Erwin Moller
Sep 8 '05 #2
Erwin Moller wrote:
Stelios G. Sfakianakis wrote:

Hello,
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:

<?php

$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?
Thanks!

Hi,

$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:
$_POST["name"];

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

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

Read on here: http://nl2.php.net/features.file-upload

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


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
http://www.php.net/wrappers.php :

<quote>
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
enctype="multipart/form-data".
</quote>

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!
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. :-)

Regards,
Erwin Moller

Sep 8 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Chuck Anderson | last post by:
Can anyone point me in the right direction? I want to use Php to automate confirmation of someone joining an email list by them replying to an email (so they don't have to have a browser?). I...
6
by: Phil Powell | last post by:
In TCL it would be written this way: I guess what I need is the PHP equivalent of TCL's gets command (see http://www.astro.princeton.edu/~rhl/Tcl-Tk_docs/tcl8.0a1/gets.n.html for more...
2
by: comp.lang.php | last post by:
function &getResponse() { /*---------------------------------------------------------------------------------------------- New 7/29/2005: Windows can use STDIN, however, the 'con' input data...
1
by: | last post by:
I want to run PHP scripts from my C++ program. I can run "php -n my_script.php" but I have 2 problems: 1. From my C++ program I want to pass to PHP script a data structure (a C++ map). I think...
17
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php"...
0
by: todddeluca | last post by:
I am posting code for calling almost any python function from php, because it seems generally useful. Please feel free to suggest improvements or tell me this has already been done better...
8
by: comp.lang.php | last post by:
<? error_reporting(E_ALL & ~E_NOTICE); if (@is_file('functions.inc.php')) require_once('functions.inc.php'); $xml = preg_replace('/(>)+(<)/', '$1$2', @file_get_contents('php://stdin')); $parser...
2
by: yawnmoth | last post by:
For learning purposes, I'd like to create a PHP script that'll output the system time every minute and, at the same time, will process "command line" commands as I type them into STDIN. eg. If...
2
by: BDthatsme | last post by:
I can't get any of the various examples of keyboard input to work using command line PHP. I have Windows XP Pro SP 2 and PHP 5.1.6 (cli) (built: Aug 23 2006 16:35:53). I can't find any info...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.