Saving from a form to a text file problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
andys22
Forum Newbie
Posts: 7
Joined: Wed Mar 15, 2006 10:01 am

Saving from a form to a text file problem

Post by andys22 »

I am trying to save text from my form into a text file, however I am getting errors. I cannot see a problem with the code:

Code: Select all

<?php
    $data = "wiki_text";
    $filename="wiki.data";
    
    // Open the file for truncated writing 
    $fp = fopen($filename, "w") or die("Couldn't open file for writing"); //this is line 14
    $numBytes = fwrite($fp, $data) or die("Couldn't write values to file!"); 

    fclose($fp); 
  echo "Wrote $numBytes bytes to wiki.data successfully!";
  ?>
It is returning this error:

Warning: fopen(wiki.data): failed to open stream: Permission denied in /public_html/updatewiki.php on line 14
Couldn't open file for writing

Can anyone help me out please? thanks

Andy
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

have you tried chmod(), umask() or chown()
andys22
Forum Newbie
Posts: 7
Joined: Wed Mar 15, 2006 10:01 am

Post by andys22 »

I'm a newbie so I have not come across those commands as yet. if you could give me some example of how it might help I will try it. Thanks
Post Reply