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 2 of 2
  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

    changing ownership of a file to server user

    Hello;
    This is about file and directory ownership (on Unix based servers).
    The situation:
    I have a file to post via ftp on a server.
    The file ownership is mine as the ftp account holder for the hosting service server.
    The same is true for directories I create.
    If I write php scripts that create files and directories, the ownership of those files
    and directories are the web server user; EG nobody, or _www or whatever.
    I can write scripts to change ownership to me. But if I am the owner of the file
    or directory, I cannot change the ownership to the web server user with a php script(?)
    The question:
    IS there an ftp command for changing ownership of files and directories to the
    web server user? The only other way is to ssh into the server and know the root
    password, not likely with a remote host.
    This is a security consideration. IF all the files are mine, then the write permission
    for directories and files have to include 'everyone'.

  • #2
    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 figured it out...

    open and read the file, unlink it and then rewrite it. Since files crated by php script
    will assign the file created to the php (web server) user.
    However, why does unlink() work on a file that is not owned by the web server?
    Code:
    $_fr = fopen('<fileName>', 'r');
       $_fileStr = fread($_fr, filesize(<fileName>));
       fclose($_fr);
       unlink(<fileName>);
       $_fw = fopen(<fileName>, 'w');
       fwrite($_fw, $_fileStr);


  •  

    Posting Permissions

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