[php-src] Issue #8239: For php://input fread() writes temp files
| From: | raubv0gel | Date: | Tue, 22 Mar 2022 12:12:15 +0000 |
| Subject: | [php-src] Issue #8239: For php://input fread() writes temp files | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-240454@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/8239
Author: raubv0gel
### Description
The following code:
Please, see Stackoverflow for some
discussion.
```php
<?php
// index.php
$postBodyResource = fopen("php://input", 'rb');
while (!feof($postBodyResource)) {
$data = fread($postBodyResource, 5 * 1024);
}
fclose($postBodyResource);
```
and Apache 2.4 config
```
Alias "/api" "${SRVROOT}/htdocs/Api"
<Directory "${SRVROOT}/htdocs/Api">
RewriteEngine On
RewriteCond %{REQUEST_FILEaNAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
Script POST "index.php"
Script PUT "index.php"
php_value enable_post_data_reading Off
</Directory>
```
Resulted in this output:
If I do a HTTP POST (Content-Type: application/octet-stream) at http://localhost/api with a body larger than 16 kB, PHP creates a
temp file at sys_temp_dir or upload_dir that stores the whole content of the stream php://input
while doing fread().
But I expected this output instead:
At least there should be a configuration option to disable writing the temp files.
### PHP Version
>= PHP 7.4
### Operating System
Windows 10 21H2