fopen() in php

$fp = fopen(“$document_root/../orders/orders.txt”, ‘w’);

When fopen() is called, it expects two, three, or four parameters. Usually, you use two

Table of files mode of fopen()

ModeMode NameMeaning
rReadOpen the file for reading, beginning from the start of the file.
r+ReadOpen the file for reading and writing, beginning from the start of the file
wWriteOpen the file for writing, beginning from the start of the file. If the file
already exists, delete the existing contents. If it does not exist, try to
create it.
w+WriteOpen the file for writing and reading, beginning from the start of the file.
If the file already exists, delete the existing contents. If it does not exist,
try to create it
xCautious
write
Open the file for writing, beginning from the start of the file. If the file
already exists, it will not be opened, fopen() will return false, and PHP
will generate a warning
x+Cautious
write
Open the file for writing and reading, beginning from the start of the file.
If the file already exists, it will not be opened, fopen() will return false,
and PHP will generate a warning
aAppendOpen the file for appending (writing) only, starting from the end of the
existing contents, if any. If it does not exist, try to create it.
a+AppendOpen the file for appending (writing) and reading, starting from the end of
the existing contents, if any. If it does not exist, try to create it.
bBinaryUsed in conjunction with one of the other modes. You might want to use
this mode if your file system differentiates between binary and text files.
Windows systems differentiate; Unix systems do not. The PHP developers
recommend you always use this option for maximum portability. It is the
default mode
tTextUsed in conjunction with one of the other modes. This mode is an option
only in Windows systems. It is not recommended except before you have
ported your code to work with the b option.
Table of files mode of fopen()

Leave a Comment