In this topic we discuss on php file handling that include the Create, Open, Read, Write, Append, Close, and Delete file using php file handling concept the following example of all type of file operation in php.
<?php
$my_file = 'file.txt';
$ha_file = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
?>
<?php
$my_file = 'file.txt';
$ha_file = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
?>
<?php
$my_file = 'file.txt';
$ha_file = fopen($my_file, 'r');
$data = fread($ha_file,filesize($my_file));
?>
<?php
$my_file = 'file.txt';
$ha_file = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
$data = 'This is the data';
fwrite($ha_file, $data);
?>
<?php
$my_file = 'file.txt';
$ha_file = fopen($my_file, 'a') or die('Cannot open file: '.$my_file);
$data = 'New data line 1';
fwrite($ha_file, $data);
$new_data = "\n".'New data line 2';
fwrite($ha_file, $new_data);
?>
<?php
$my_file = 'file.txt';
$ha_file = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
//write data here
fclose($ha_file);
?>
<?php
$my_file = 'file.txt';
unlink($my_file);
?>