Aim:
Reading and Writing the files using PHP
Source Code:
Week-4/Week4.php
<html>
<head>
<title> File Operations in PHP </title>
</head>
<body>
<?php
$filename = "myfile.txt";
echo "<br>";
$fp = fopen($filename, "w");
fwrite($fp,'PHP is a Scripting Language');
echo "Data written successfully..";
fclose($fp);
echo "<br>";
$fp = fopen($filename, "a");
fwrite($fp,' at server side');
echo "Data appended successfully..";
fclose($fp);
echo "<br>";
$fp = fopen($filename, "r");
$content = fread($fp, filesize($filename));
echo "<strong>Content in the file :</strong> <br> $content";
fclose($fp);
?>
</body>
</html>
Output:


No comments