Tools, FAQ, Tutorials:
Appending Data to the End of a File in PHP
How To Append New Data to the End of a File in PHP?
✍: FYIcenter.com
If you have an existing file, and want to write more data to the end of the file, you can use the fopen($fileName, "a") function. It opens the specified file, moves the file pointer to the end of the file, and returns a file handle. The second argument "a" tells PHP to open the file for appending. Once the file is open, you can use other functions to write data to the file through this file handle. Here is a PHP script example on how to use fopen() for appending:
<?php
$file = fopen("/temp/cgi.log", "a");
fwrite($file,"Remote host: 64.233.179.104.\r\n");
fclose($file);
$file = fopen("/temp/cgi.log", "a");
fwrite($file,"Query string: cate=102&order=down&lang=en.\r\n");
fclose($file);
?>
This script will write the following to the file:
Remote host: 64.233.179.104. Query string: cate=102&order=down&lang=en.
As you can see, file cgi.log opened twice by the script. The first call of fopen() actually created the file. The second call of fopen() opened the file to allow new data to append to the end of the file.
⇒ Reading One Line of Text from a File in PHP
⇐ Opening a File for Writing in PHP
2016-12-02, ∼2302🔥, 0💬
Popular Posts:
How to view API details on the Publisher Dashboard of an Azure API Management Service? You can follo...
How to dump (or encode, serialize) a Python object into a JSON string using json.dumps()? The json.d...
How To Read the Entire File into a Single String in PHP? If you have a file, and you want to read th...
What properties and functions are supported on http.client.HTTPResponse objects? If you get an http....
Where to find tutorials on HTML language? I want to know how to learn HTML. Here is a large collecti...