Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends...


I am very new to php just starting learning from internet. I seen some examples for file handling. But when I'm following the same procedure to **file writing** it's not working.

The Reading function is working file. But writing to a file isn't working. I have also tried to use **file_put_content** function to write. :(

<?php
    if(isset($_POST['submit1'])){
    $fileName = "Text.txt";
    $fh = fopen($fileName,"a") or die("can not open the file to write");

    //Writing to a file
    $newData = "Hello This is new Data";
    fwrite($fh,$newData);
    fclose($fh);

    //Reading a file -- Working
    $text = fopen("Text.txt","r") or die ("can not open the file to read");
    while(!feof($text))
    {
        $myLine = fgets($text);
        print $myLine;
    }
    fclose($text);
    }

?>

Please Guide me..
Thanks
Posted

1 solution

The problem is probably with your directory permission. Fix the issue first and then try
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900