From "should be simple" file-writing-reading-etc. tutorial:

$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT']; // F:/wamp/www
// open file for appending
@ $fp = fopen("$DOCUMENT_ROOT/../orders/orders.txt", 'ab'); 
/*From instructions:  "This directory is outside the document tree, 
for security reasons. In this case, we do not want this 
file to be web accessible except through the interface that we provide" */

flock($fp, LOCK_EX);/*Outputs: Warning: flock() expects parameter 1 to be resource, boolean given in F:\wamp\... ...on line 68.*/

1)So F:/wamp/www is the 'document root' and if I'm not mistaken this part of the code "$DOCUMENT_ROOT/../orders/orders.txt" writes (or should write) to F:/wamp/orders/orders.txt if you write it in absolute path? Please confirm if I got that right?🙂

2)Then, how do you allow script to write to upper ('parent') directory of /www?

    1.) That's correct
    2.) Well, this is a permissions issue. If the user that PHP (and sometimes the web-server) is/are running as does not have permission to write to the F:/wamp folder, then you probably can't write to any sub-folders except the "www" folder. On the other-hand, you could just have missed the permissions on the "orders" folder or "orders.txt" file.

    There are a couple ways to fix this. One is to allow the user to write to that directory/file. The other is to move everything down 1 level (so it's /www/orders and /www/web_root/<your web files>) and then include a .htaccess file which forwards all requests from "/www/" to "/www/web_root/" effectively making your "/www/orders/" directory "above" the document root without actually having it be outside the permissions of the server & PHP 😉 It's a handy trick; however, you have to be sure not to delete the .htaccess file 😉

      Write a Reply...