Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fopen in binary mode #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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