File Handling in PHP
File handling in PHP is very easy and effective. Not only files, we can open urls also using php’s file functions.
Few important file functions in php are:
- file();
- file_get_contents();
- file_put_contents();
- fopen();
- fclose();
- fread();
- file_exists();
- delete();
- filesize();
- fwrite();
- is_dir();
- is_writable()
A simple program to read a file content;
$fp = fopen("test.txt","r+");
$contents = fread($fp);
flcose($fp);
A simple PHP program to write into a file;
$fp = fopen("test_new.txt","w");
fwrite($fp,$content);
fclose($fp);