This document discusses PHP file handling functions. It explains how to open, read, write, append, close and delete files using PHP functions like fopen(), fread(), fwrite(), fclose() and unlink(). It provides code examples to open a file in write mode, read the contents of a file, write data to a file, append data to a file without overwriting existing contents, close an open file stream, and delete a file. PHP file handling allows dynamically managing files through these basic file operations.
1 of 5
More Related Content
Php file handling in Hindi
1. PHP file handling
Introduction to PHP file handling in Hindi
Opening a file with PHP in Hindi
Reading file with PHP in Hindi
Writing a file with PHP in Hindi
Closing a file with PHP in Hindi
Introduction to file handling
languages files PHP functions
provide , 爐爐 easily files handle Files
handle ability PHP top scripting languages group
web applications database , simple data text
files store 爐 PHP files 爐爐 6
operations perform
Opening a file
Reading a file
Writing a file
Appending a file
Closing a file
Deleting a file
operations PHP perform , 爐
Opening a file
Files open PHP fopen() provide method 2
argument pass 爐 argument file , 爐 爐爐
mode open mode PHP file 爐 modes open
modes character represent
2. modes 爐 爐 operations 爐
modes
Mode
s
Explanation
r mode files read
r+ mode file read 爐 file write
w mode files write file 爐 create
w+ mode file read/write operation perform
a mode 爐 file content delete content add
a+ mode 爐爐 file read 爐 data append
x mode 爐爐 file data
write file file 爐 error
爐
x+ mode 爐爐 read 爐 write
File operation perform 爐 file
open PHP file open
Opening a file
<?php
$myFile = fopen(myFile.txt,w);
?>
file open 爐爐 file mode
爐爐 open according 爐 operation perform
Reading from a file
3. File read 爐爐 2 functions 爐 爐爐
fread() function function 爐爐 file length
爐 File length pass , compiler 爐
file content 爐爐 filesize()
method 爐爐 file pass PHP file read
Reading from a file
<?php
$file1 = fopen(myFile.txt,r+); // open file
$filesize($file1);
$filedata = fread($file1,$filesize);
?>
Writing to a file
file data store 爐爐 fwrite() function
function file pointer 爐 data pass File pointer variable ,
爐爐 file open point PHP data write
Writing to a file with PHP
<?php
$myFile = fopen(myFile.txt, w);
fwrite(myFile,This website is cool!);
?>
Appending to a file
4. 爐爐 existing file data write , file previous data
delete 爐爐 previous data delete
end new data add 爐爐 file a mode open
爐 fwrite() function data 爐爐 write
Appending to a file
<?php
$myFile = fopen(filename.txt,a); //opening with a mode
fwrite($myFile,and I am also cool!);
?>
Closing a file
Operations complete 爐爐 file stream close
PHP fclose() method provide method file pointer pass
Closing a file
<?php
$myFile = fopen(filename.txt,a); //opening with a mode
// do some operations here
fclose($myFile)
?>
Deleting a file
5. 爐 爐爐 file delete PHP unlink
method provide
Deleting a file
<?php
$myFile = fopen(filename.txt,a); //opening with a mode
//perform some operations here
unlink($myFile)
?>
PHP file handling 爐爐 dynamically files handle