Skip to content

Conversation

divinity76
Copy link

some shitty OS's (for example MS Windows) may corrupt binary data like the sample .jpg files with fopen text mode, and the default fopen mode if none is specified, may be text mode (the only instances i can think of off-hand is MS Windows and classic MacOS, and PHP does not even support classic MacOS, but Windows is supported), quoting the docs:

The default translation mode depends on the SAPI and version of PHP that you are using, so you are encouraged to always specify the appropriate flag for portability reasons. You should use the 't' mode if you are working with plain-text files and you use \n to delimit your line endings in your script, but expect your files to be readable with applications such as notepad. You should use the 'b' in all other cases.

so.. for Windows-portability reasons, one should pretty much always fopen in binary mode.

some shitty OS's (for example MS Windows) may corrupt binary data like the sample .jpg files with fopen text mode, and the default fopen mode if none is specified, may be text mode (the only instances i can think of off-hand is MS Windows and classic MacOS, and PHP does not even support classic MacOS, but Windows is supported), quoting the docs:

> The default translation mode depends on the SAPI and version of PHP that you are using, so you are encouraged to always specify the appropriate flag for portability reasons. You should use the 't' mode if you are working with plain-text files and you use \n to delimit your line endings in your script, but expect your files to be readable with applications such as notepad. You should use the 'b' in all other cases.

so.. for Windows-portability reasons, one should pretty much always fopen in binary mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant