how to check server permissions

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
Blondy
Forum Commoner
Posts: 32
Joined: Thu Mar 06, 2008 5:55 pm

how to check server permissions

Post by Blondy »

hi
I need a code to see does the server give the script write & delete permissions or not.
thanks
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: how to check server permissions

Post by John Cartwright »

We are talking about file permissions?

http://ca.php.net/manual/en/function.fileperms.php
Blondy
Forum Commoner
Posts: 32
Joined: Thu Mar 06, 2008 5:55 pm

Re: how to check server permissions

Post by Blondy »

any other
(more simple) solutin?
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: how to check server permissions

Post by Syntac »

That's as simple as it gets, my friend.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: how to check server permissions

Post by John Cartwright »

Did you bother to read the manual? Assuming you want an octal value,

Code: Select all

echo substr(sprintf('%o', fileperms('/path/to/your/file.txt')), -4);
would return something like 0777 if it was writtable.

:x
Blondy
Forum Commoner
Posts: 32
Joined: Thu Mar 06, 2008 5:55 pm

Re: how to check server permissions

Post by Blondy »

I can't echo some 0777 for user
I just want to see if can my script create a file or not, delete a filer not somehow I solved it thanks
bro if you have a way will be good to know!
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: how to check server permissions

Post by Eran »

Do you know how to program? do you know PHP?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: how to check server permissions

Post by John Cartwright »

Blondy wrote:I can't echo some 0777 for user
I just want to see if can my script create a file or not, delete a filer not somehow I solved it thanks
bro if you have a way will be good to know!
You don't have to echo anything.

Code: Select all

 
if (substr(sprintf('%o', fileperms('/path/to/your/file.txt')), -4)) {
   //you have read/write/execute permission
   //do whatever you want
}
:x
User avatar
airy
Forum Newbie
Posts: 20
Joined: Fri Jul 11, 2008 2:53 am

Re: how to check server permissions

Post by airy »

try it and then you know the answers
try to create a file,u'll know weather you can.try to delete a file and u'll know weather you have the permission
Blondy
Forum Commoner
Posts: 32
Joined: Thu Mar 06, 2008 5:55 pm

Re: how to check server permissions

Post by Blondy »

try it and then you know the answers
try to create a file,u'll know weather you can.try to delete a file and u'll know weather you have the permission
I've doneit the way you say as I said!
Do you know how to program? do you know PHP?
Yes Cause I'm here to learn
:crazy:
Post Reply