Click here to Skip to main content
15,943,294 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. :(

    $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";

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


Please Guide me..

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