The fopen command is used to open a specific file.
$myfile = fopen ("filename.ext","mode");
Before opening a file however, you have to decide on what will be happening to the file :
1. Do you want to open the file just to read the contents? 2. Do you want to be able to write information to the file? 3. Do you want to delete the current contents of the file and replace them with new data? 4. Do you want to write to the start or end of the file?
Once you've decided on the outcome, the correct MODE is used in opening the file. The MODE part will set the open file for :
| r |
Read only. Pointer set at top of file data. |
| r+ |
Read and write. Pointer set at top of file data. |
| w |
Write only. Any existing data will be deleted. If file is not found, PHP will create one. |
| w+ |
Read and write. Any existing data will be deleted. If file is not found, PHP will create one. |
| a |
Appending only. New data will be written at the end of the existing file data. |
| a+ |
Read and appending. New data will be written at the end of the existing file data. | When you are done with the data transfer to or from the file, it must be closed.
fclose ($myfile);
----------------- Article by David Stanley. Visit his site http://www.htmlite.com. Reprinted with permission.
|