PHP File Handling


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(“”, “r”);


Reading from file:

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


writing to file:

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