RE: [PHP-WIN] can't read binary files containg '0x0' character
| From: | Svensson, B.A.T. | Date: | Mon, 15 Oct 2001 11:54:56 +0000 |
| Subject: | RE: [PHP-WIN] can't read binary files containg '0x0' character | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-9850@lists.php.net to get a copy of this message | ||
Feeding the function with the proper arguments will
allow one to make things (almost) behave in the way
one would like to predict them. However trying to relay
on special features found in one API is just asking
for trouble when migrating them to another API.
Assuming php just wraps C's fopen(), then the possible
mode to provide fopen() with should be:
"r", "w", "a"
"rb", "wb", "ab"
"r+", "w+", "a+"
"r+b" or "rb+",
"w+b" or "wb+",
"a+b" or "ab+",
r and w is read respectively write (text) open mode.
"w" mode creates a new file or truncates an existing
file on opening. Mode "a" opens the file in append
mode and adds data to the end of the file.
An Additional mode "b" opens the file in binary mode
- that is no character translation is performed.
Adding mode "+" opens the file for both reading and
writing. However, "w+" creates a new file if none
existing or truncates an existing file on opening.
Opening a file in binary mode will ensure that you
read the raw file. Opening a file in text mode makes
the system parse the file before returning data to
the API programmer. The behavior of text mode is
system dependent, even sometimes compiler dependent.
For example on some platforms (not mentioning any
particular, but it is M$ environment) closing a text
file in write mode might cause additional junk be
appended to the end of the file - causing lots of
problem for other applications.
Cheers,
/Anders
>-----Original Message-----
>From: Roland Divin [mailto:xdivr03@vse.cz]
>Sent: Friday, October 12, 2001 9:33 PM
>To: php-windows@lists.php.net
>Subject: Re: [PHP-WIN] can't read binary files containg '0x0' character
>
>
>Thanks, you're right. Now it works even using dll module (not CGI) version.
>Anyway it is strange that the behavior of the fread function is conditioned
>whether I use dll module or CGI...
>
>Roland
>
>"Mark" <maggelet@mminternet.com> píse v diskusním príspevku
>news:200110121918.f9CJIEr06509@zeus.mminternet.net...
>On Fri, 12 Oct 2001 21:00:24 +0200, Roland Divin wrote:
>>Hi,
>>I can'r read binary file that contains '0x0' character. Reading
>>process
>>stops after reading '0x0' character on windows version of PHP. On
>>Linux it
>>does not.
>>
>>That same code gives another result on windows then on linux. Why?
>>(Consider file text.txt is contaning '0x0' characters. I'm using
>>PHP4 build
>>from Jun 22 2001.)
>>
>>$filename = "text.txt";
>>$fd = fopen ($filename, "r");
>
>should be "rb" for binary files.
>
>>$contents = fread ($fd, filesize ($filename));
>>fclose ($fd);
>>echo $contents;
>>echo strlen($contents);
>>for($i=0;$i<strlen($contents);$i++)
>>{ echo "$i:".ord($contents[$i])."<br>"; }
>>
>>Isn't it bug?
>>
>>Thanks
>>Roland Divin
>>
>>
>>
>
>
>--
>Mark, maggelet@mminternet.com on 10/11/01
>
>
>
>
>
>--
>PHP Windows Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net
>For additional commands, e-mail: php-windows-help@lists.php.net
>To contact the list administrators, e-mail:
>php-list-admin@lists.php.net
>