relative path issue

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
DrT
Forum Newbie
Posts: 8
Joined: Wed May 15, 2002 11:01 am

relative path issue

Post 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
User avatar
enygma
Site Admin
Posts: 175
Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx

Post 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...
DrT
Forum Newbie
Posts: 8
Joined: Wed May 15, 2002 11:01 am

Post 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! :(
User avatar
enygma
Site Admin
Posts: 175
Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx

Post 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....
DrT
Forum Newbie
Posts: 8
Joined: Wed May 15, 2002 11:01 am

Post 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 :D
User avatar
enygma
Site Admin
Posts: 175
Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx

Post 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
DrT
Forum Newbie
Posts: 8
Joined: Wed May 15, 2002 11:01 am

Post 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!
Post Reply