|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-12-31 01:21 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 15 05:00:01 2025 UTC |
Description: ------------ I write a script which reads a file from STDIN, and writes it out the content of it to a new file. It worked fine with php 4.3.4, but when I upgraded to any newer version, then it failed to read the whole file from stdin. I expected to read the file into a 128000 bytes buffer but it reads only 8192 bytes instead of 128000 bytes. Reproduce code: --------------- <? $file_length = 6596594; define("UPLOAD_BUFFER",128000); if (!$fp = fopen("test.data","w")) { die("file open error"); } $count = (($file_length / UPLOAD_BUFFER)); echo "\nmax i should be: ".$count; for ($i = 1; $i < $count; $i ++) { $str = fread(STDIN, UPLOAD_BUFFER); echo "\ni: ".$i." length:".strlen($str); fwrite($fp, $str); } $remainder = $file_length % UPLOAD_BUFFER; if (0 != $remainder) { $str = fread(STDIN, $remainder); echo "\nlast length:".strlen($str); fwrite($fp, fread(STDIN, $remainder)); } fclose($fp); ?> Expected result: ---------------- If I run my script with this command: php -q ./my.php < file_with_size_of_6596594_bytes.bin I expect to get a new file created (test.data), with the same content as the file_with_size_of_6596594_bytes.bin. Actual result: -------------- As a result a new file created (test.data), which is 425984 bytes long. 425984=51*8192+8192 But, it shuld be 6596594=51*128000+68594