The readfile() function reads a file and writes it to the output buffer.
JPEG = Joint Photographic Experts Group
GIF = Graphics Interchange Format
PNG = Portable Network Graphics
PSD = Photoshop Document
SVG = Scalable Vector Graphics
<!DOCTYPE HTML>
<html>
<head>
<title>File Handling - readfile()</title>
</head>
<body>
<?php
echo readfile("MY_FILE.txt");
?>
</body>
</html>
The PHP fwrite() function is used to write content of the string into file.
<!DOCTYPE HTML>
<html>
<head>
<title>File Handling - fwrite()</title>
</head>
<body>
<?php
$fp = fopen('MY_FILE_2.txt', 'w');//open file in write mode
fwrite($fp, 'Free Time Learning ');
fwrite($fp, 'Free Time Learn');
fclose($fp);
echo "File written successfully";
?>
</body>
</html>
The fclose() function is used to close an open file..
The fclose() requires the name of the file (or a variable that holds the filename) we want to close:
<!DOCTYPE HTML>
<html>
<head>
<title>Close File - fclose()</title>
</head>
<body>
<?php
$file = fopen("MY_FILe.txt", "r");
echo fread($file,filesize("MY_FILE.txt"));
fclose($file);
?>
</body>
</html>