As the error said, u dont have permision to create file, so is not about script ...

    How do I give myself permission?

      Didn't u restrict your access from your web server?

        I have seen this used for file permission, it is done before using fopen().

        umask(0777);//add before using fopen in your script.
        foreach ($_POST as $key=>$value){
             $recieved .= "$key = $value\r\n";
        }
        
        $printout = fopen("variables.txt", "w");
        fwrite($printout, $recieved);
        fclose($printout); 

          I haven't restricted my own access at all unless I did it accidentally somehow. How would I check?

          Thanks for the code Houdini, but I think I need to sort this out rather than find a workaround.

            It is not a workaround what it does is sets the permission first then the fopen() should work with the file. Would you consider it a workaround to use session_start() before calling lets say $_SESSION['somevariable'] = $somevariable? No because it is required or the assignment will fail.

              Sorry Houdini, but I am very new to PHP. Surely there is some way I can change permissions globally so that writing to/from all/any file is not an issue.

                Tried using unmask and I get:

                Fatal Error: call to undefined function unmask();

                  Sorry about that.

                  Now I'm getting the original error message and:

                  Notice:Undefined variable: recieved in /Users/myUsername/Sites/etc /vartest.php on line 10

                  Warning: fclose():supplied argument is not a valid stream resource in /Users/myUsername/Sites/etc /vartest.php on line 11

                    arkum wrote:

                    Notice:Undefined variable: recieved in /Users/myUsername/Sites/etc /vartest.php on line 10

                    This is because in foreach u try to concat a string to $recieved and u didnt declare it first.

                    arkum wrote:

                    Warning: fclose():supplied argument is not a valid stream resource in /Users/myUsername/Sites/etc /vartest.php on line 11

                    This is because u couldnt open the file but u close it, u should call this function only if fopen return true ...

                      Ok, but that still doesn't solve the permissions problem.

                        No, it has nothing to do with the permission problem, I have never encounter a permission problem on a local computer, this occur only on hostings, what OS do u have?

                          Thanks for getting back to me bogo.

                          Intel macbook pro with OSX. Tried changing folder permissions all over the place to group aswell as user, but still no good.

                          Just out of interest, how should my code have read in relation to the undeclared var?

                            arkum wrote:

                            Just out of interest, how should my code have read in relation to the undeclared var?

                            /*declare $recieved variable */
                            $recieved = '';
                            foreach ($_POST as $key=>$value){ 
                                 $recieved .= "$key = $value\r\n"; 
                            }

                              Thanks a lot for your help. I think I'm going to call it a day.

                                Try this simple script and see if you can write a file at all

                                <?php
                                	$filename="testtext.txt";
                                    $myarray[] = "This is line one";
                                    $myarray[] = "This is line two";
                                    $myarray[] = "This is line three";
                                    $mystring = implode("\n", $myarray);
                                    $handle = fopen($filename, "wb");
                                    $numbytes = fwrite($handle, $mystring);
                                    fclose($handle);
                                    print "$numbytes bytes written\n";
                                ?> 
                                  Write a Reply...