It's possible, but the implementation is going to be rather awkward. The main obstacle is that the handling of multipart POST request is hardcoded into PHP. It will always save the files to temporary locations before invoking your script. One workaround is to set up PHP-CLI as a CGI script. As the CLI version of PHP is not HTTP-aware, it lets you get your hands on the incoming data.
The .CGI file will look something like this:
#!/usr/local/src/php-4.3.4/sapi/cli/php
<?php
// populate $_GET
parse_str($_ENV['QUERY_STRING'], $_GET);
// get the session id from the cookie
parse_str($_ENV['HTTP_COOKIE'], $_COOKIE);
$session_name = ini_get("session.name");
$session_id = $_COOKIE[$session_name];
// get the length of the request body
$length = (int) $_ENV['CONTENT_LENGTH'];
// read the POST data
$stdin = fopen("php://stdin", "rb");
while($chunk = fread($stdin, 4096)) {
[...]
}
?>
Parsing the RFC1867 request is non-trivial. Coordinating the uploading party with the downloading party will also be rather tricky, I imagine.