PHP File Write function
We can write to a file by using fwrite() function PHP. Please note that we have to open the file in write mode and if write permission is there then only we can open it in write mode. If the file does not exist then one new file will be created. We can change the permission of the file also. However we can check the presence of a file by using file_exists function. You can read the content of a file by using fopen() function in PHP. This is the way to write entries to a guestbook, counter and many other scripts if you are not using any database for storing data. . Here we will see how to write to a file.
Create one page hit counter where a incremental number is stored in a text file each time the file is opened..
is my content"; //
Store some text to enter inside the file
// file name
$fp = fopen ($file_name, "w");
// Open the file in write mode, if
file does not exist then it will be created.
// entering data to the file
// closing the file pointer
// changing the file permission.
Be the first to post comment on this article :
|Click here for More on PHP File functions|