PHP File Handling

PHP File Handling

Files:

In PHP it is possible to create, read, and write files on the server system. The first step is to open a file and associate it with a variable name. The variable is known as file variable. The fopen() function is used to perform the above operation of opening the form. This function takes two parameters: filename and use indicator. The use indicator is a string which specifies the operations that can be performed on the file. The possible values of use indicator are:

“r” , “r+” , “w” , “w+” , “a” and “a+”

 

For example:

$filevar = fopen(“filename” , “use indicator”);

 

$filevar  = fopen(“test.data”, “r”);

 

Reading from file:

$filedata = fread($filevar, filesize(“test.data”);

 

writing to file:

$byteswritten = fwrite($filevar, $content);