Page 1 of 1
relative path issue
Posted: Thu May 16, 2002 2:04 am
by DrT
I can use a small script to create a new text file in the same directory as the script is running using $fp=fopen("test.txt","w") and that works fine but if I try to create it in a different directory using $fp=fopen("../Data/test.txt","w") it fails saying I don't have the permission to do this! I have full 777 permissions set on both the directory the script lives in and on the Data directory so what am I doing wrong?
Thanks for any thoughts you may have on this.
Tim West
Posted: Thu May 16, 2002 7:56 am
by enygma
be sure to use the full path, not a relative path. I think that confuses PHP.
so, instead of
$filename="./test.txt";
use
$filename="/export/home/myname/text.txt";
or whatever the location is...
Posted: Thu May 16, 2002 8:00 am
by DrT
I tried that, I used $DOCUMENT_ROOT."/Data/test.txt" and still got told I didn't have the permission so I even put it in manually and same result

I'm guessing its something to do with permissions but I've got all the folders set to 777 and all the files I can find too!

Posted: Thu May 16, 2002 8:02 am
by enygma
echo the path and make 100% sure that it's what you think it is.
Then, if it's still like that, be sure that the user you're running the webserver as has write permissions to the directory.
Other than that, I dunno....
Posted: Thu May 16, 2002 8:09 am
by DrT
Now there goes that "User" thing again! I'm used to NT where I don't see these problems so whats this user, group, world thing and how does the script/server know which one I belong to? I just simply call the script from a browser window but in the long term it will be called from a Flash program

Posted: Thu May 16, 2002 8:26 am
by enygma
usually, the webserver runs as the "nobody" user with normal user read/write restrictions. so, as long as the directory is world-writeable, it should be fine....
chmod 755 directory
Posted: Thu May 16, 2002 8:37 am
by DrT
Yes, I've got the directory set up to 777! I can create the file from the script fine if its in the same directory as the script, the problem comes when I try to create the file in a different directory from the script. I created a sub directory to where the script is and set its permissions to 777 and then tried to get the script to create the file in it and I got the "not allowed" message. Seems very strange to me!