SEARCH YOUR SOFTWARES IN THIS SITE........

Thursday, November 26, 2009

Learn how to open PHP files..

$file_handler = fopen($file, $mode)

You must assign the function to a variable, as above. This is referred to as a file pointer. You use the file pointer to reference the open file throughout your script.

The fopen() function takes two arguments:
$file is the name (and path, if required) of the file.

$mode is one of a list of available modes:
1. r— Open the file as read-only. You cannot write anything to the file. Reading begins at the beginning of the file.
2. r+ — Open the file for reading and writing. Reading and writing begin at the beginning of the file. You will delete existing contents if you write to the file without first moving the internal pointer to the end of the file.

3. w— Open the file for write-only. You cannot read data from the file. Writing begins at the beginning of the file. You will again delete contents if you write to the file without first moving the pointer to the end of the file. If the file specified by the $fie argument does not exist, then PHP attempts to create the file. Make sure your permissions are set correctly!
4. w+ — As above, but the file may also be read.

5. a— This mode is the same as the 'w' mode, with the exception that the internal pointer is placed at the end of the file. Existing contents will not be overwritten unless you rewind the internal pointer to the beginning of the file.

0 comments:

Post a Comment