2

The following code recently started returning empty strings. It works on other systems, so it doesn't appear to be a problem with the code itself. I literally eliminated all of the server-side code, and it still did the same thing. I also tried using file_get_contents to no avail, just kind of shooting in the dark.

$fileStream = fopen('php://input', 'rb');

$fileData = '';
while ($buffer = fread($fileStream, 4096)) {
    $fileData .= $buffer;
}

Server: Zend Server 5.1.0 (Apache 2.2.3)

Language: PHP 5.3.5

Front-End: Plupload (JavaScript plugin)

hakre
  • 193,403
  • 52
  • 435
  • 836
webjawns.com
  • 2,300
  • 2
  • 14
  • 34
  • 1
    Did you try using `STDIN` in place of `$fileStream` (and dropping the first line)? – Matthew Flaschen Mar 28 '11 at 18:51
  • "I literally eliminated all of the server-side code" Is this in a server-side or command-line program? – Powerlord Mar 28 '11 at 19:15
  • It's in a web application (no CLI for this feature). – webjawns.com Mar 28 '11 at 19:41
  • 6
    `php://input` cannot be opened/read when receiving a `multipart/form-data` POST, maybe that's what changed client-sided? – Wrikken Mar 28 '11 at 20:01
  • @Wrikken That's was exactly the issue. Thanks so much for your help! You saved me many hours of troubleshooting! – webjawns.com Mar 28 '11 at 20:27
  • Nice to know. If you need this functionality, you might be able to destroy the multi-part header with [mod_headers](http://httpd.apache.org/docs/current/mod/mod_headers.html), haven't tested it, but the only reason PHP normally doesn't let you read this is just a memory / optimization issue in the PHP core itself, not a real technical limitation / impossibility. I've seen a working answer somewhere on SO, but can't seem to find it right now. – Wrikken Mar 28 '11 at 20:35

1 Answers1

7

php://input cannot be opened/read when receiving a multipart/form-data POST, maybe that's what changed client-sided? – Wrikken Mar 28 at 20:01

Thanks for your help!

webjawns.com
  • 2,300
  • 2
  • 14
  • 34