Open File
fopen() returns false when the file can not be openned.
if ($fp=fopen(“test.txt”, “w”)){
//do something
}
Close File
fclose($fp);
Reading from file
fgets($fp, 1024); // get 1024 bytes
feof($fp); // end of the file
fread($fp, 16); // get 16 bytes
fseek($fp, 64); // move point to particular byte
fgetc($fp); // get the first letter
fwrite($fp, “Hello World”); //write into file
fputs($fp, “Hell world again”); // add into file
Looking Files
flock($fp, LOCK_SH); //share
flock($fp, LOCK_EX); //exclusive
flock($fp, LOCK_UN); //unlock


0 Comments on “File operation in PHP”
Leave a Comment