MCA VR-23 II Year I Semester (2-1) MCA Web Programming Lab Experiment 4

 

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");//open file in write mode    
    fwrite($fp,'PHP is a Scripting Language');
    echo "Data written successfully..";
    //close file
    fclose($fp);

    echo "<br>";
    $fp = fopen($filename, "a");//open file in write mode    
    fwrite($fp,' at server side');
    echo "Data appended successfully..";
    //close file
    fclose($fp);
    
    echo "<br>";
    //open file in read mode
    $fp = fopen($filename, "r");  
    //read content from the file
    $content = fread($fp, filesize($filename));
    //printing data of file
    echo "<strong>Content in the file :</strong> <br> $content";
    //close file
    fclose($fp);
?>
</body>
</html>


Output:

image


image

No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...