Files
File handling is an important activity of all web
application development process. Files are processed for different tasks using
the following events:
● PHP
Open a File,
● PHP
Read a File,
● PHP
Close a File,
● PHP
Write a File,
● PHP
Appending a File and
● PHP
uploading a File.
PHP Open a File
fopen() is a system function available in PHP. This
function helps to open a file in the server. It contains two parameters one for
the file and the other one specifies in which mode the file should be opened
(Read/Write).
$file_Object= fopen(“FileName”,
“Read/WriteMode”) or die(“Error Message!”);
<?php
$myfile = fopen(“Student.txt”, “r”)
or die(“Unable to open file!”);
?>
The fread() function reads from an open file. The
file object comes from fopen function.
fread($file_Object,filesize(“FileName”));
<?php
fread($myfile,filesize(“Student.txt”));
?>
The fclose() function is used to close an opened
file. The file object comes from fopen function.
fclose($file_Object);
<?php
$myfile = fopen(“student.txt”, “r”);
// some code to be executed....
fclose($myfile);
?>
The fwrite() function is used to write to a file.
fwrite($myfile, $txt);
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.