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〈=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〈=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.
PHP
Topic: Files
How To Append New Data to the End of a File?
Browse random answers:
How To Get the Directory Name out of a File Path Name?
How To Break a File Path Name into Parts?
How to open a file?
How many open modes available when a file open in PHP?
How To Remove the New Line Character from the End of a Text Line?
What is the maximum size of a file that can be uploaded using PHP and how can we change this?
How To Get the Uploaded File Information in the Receiving Script?
What does $_FILES means?
What's the difference between COPY OF A FILE & MOVE_UPLOAD_FILE in file uploading?
What Is File Upload?
How To Read the Entire File into a Single String?
How To Open a File for Reading?
How To Open a File for Writing?
How To Append New Data to the End of a File?
How To Read the Entire File into a Single String?
How To Read a Text File into an Array?
How To Append New Data to the End of a File?
How To Read One Line of Text from a File?
How To Read One Character from a File?
What's Wrong with "while ($c=fgetc($f)) {}"?
How To Read a File in Binary Mode?
How To Write a String to a File with a File Handle?
How To Write a String to a File without a File Handle?
How To Write an Array to a File without a File Handle?
How To Read Data from Keyboard (Standard Input)?
How To Open Standard Output as a File Handle?
How To Create a Directory?
How To Remove an Empty Directory?
How To Remove a File?
How To Copy a File?
How To Dump the Contents of a Directory into an Array?
How To Read a Directory One Entry at a Time?