PHP (Hypertext Pre-Processor) - Files | 12th Computer Applications : Chapter 8 : Forms and Files

Chapter: 12th Computer Applications : Chapter 8 : Forms and Files

Files

File handling is an important activity of all web application development process.

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).

Syntax:

$file_Object= fopen(“FileName”, “Read/WriteMode”) or die(“Error Message!”);

Example:

<?php

$myfile = fopen(“Student.txt”, “r”) or die(“Unable to open file!”);

?>

 

PHP Read a File:

The fread() function reads from an open file. The file object comes from fopen function.

Syntax:

fread($file_Object,filesize(“FileName”));

Example:

<?php

fread($myfile,filesize(“Student.txt”));

?>

 

PHP Close a File:

The fclose() function is used to close an opened file. The file object comes from fopen function.

Syntax:

fclose($file_Object);

Example:

<?php

$myfile = fopen(“student.txt”, “r”); // some code to be executed....

fclose($myfile);

?>

 

PHP write a File:

The fwrite() function is used to write to a file.

Syntax:

fwrite($myfile, $txt);

Tags : PHP (Hypertext Pre-Processor) , 12th Computer Applications : Chapter 8 : Forms and Files
Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
12th Computer Applications : Chapter 8 : Forms and Files : Files | PHP (Hypertext Pre-Processor)


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.