Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    213
    Thanks
    52
    Thanked 1 Time in 1 Post

    quetsion on stat function

    from Wikipedia entry for stat function (in c):
    The st_mode field is a bit field. It combines the file access modes and also indicates any special file type.
    I believe that the entry for stat in php manual references this.

    How would you interpret this to determine the files access perms?

    (for the sake of custom error handling or whatever)

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You mean the permission mode? I don't think there's a built in for that, but it simply returns an integer representing the mode for it. So if I have a file listed as 33279 (100777), than that's a file with read, write and execute for owner, group and everyone. It's easy to write this if you just use bit masking, lets see I think I've seen this in the manual somewhere.
    Here we go, there's an example under the fileperms: PHP: fileperms - Manual
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    213
    Thanks
    52
    Thanked 1 Time in 1 Post
    I did query the php list and got the same reference. Thank you for your time and attention.
    Now, I have a question about get user name from uid value if that is possible. It's either
    registered ftp user or web server user, at least that would be the possibilities I work with.
    I am working on CMS system and want to change ownership of files and directories I create
    that need web server permissions to write to. In this case I don't want permissions set to
    everyone.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    You don't need to know the uid -> login name association to do that, you can change the mode or ownership without knowing who the current information belongs to so long as you own it.
    You can determine the login name from a uid by executing the command line call for getent passwd $uid. I believe apache declares an environment variable as well for its own username.

    Most of what you described will have nothing to do with PHP. If you've moved a file with ftp onto a server, PHP isn't going to be capable of changing the mode or the ownership unless the ownership is transferred to the user running the PHP executable anyway. This are configuration settings that you have to do at the terminal level before anything is done. This is why, especially in the old days with CGI processes being more common for PHP, mode was always changed to 666 or 766 as a part of installation instructions.
    After that, PHP can then make any files it needs using the webserver as the login user. That automatically gives it the ownership it requires. You shouldn't be needing to write to any code files anyways, so there's no reason to pre-construct a configuration doc if you want it to be writable.

    tldr: There's no reason to pre-create any files (or even directories for that matter) that you are writing to. Let Apache and PHP do the heavy lifting when its required and save the headache of determining file ownership.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •