Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 3 of 3

This is a discussion on MKDIR()? Problems in the Shared & Semi-Dedicated forum
With my ongoing coding I make a directory Code: if(@ !mkdir("/home/parkswc/nettech/".$UserName, 0777)) { echo "EXPLAIN USER NAME IS TAKEN"; } Everything works fine except the ...

  1. #1
    JPC Member
    Join Date
    May 2002
    Posts
    20

    MKDIR()? Problems

    With my ongoing coding I make a directory

    Code:
    if(@ !mkdir("/home/parkswc/nettech/".$UserName, 0777)) {
    echo "EXPLAIN USER NAME IS TAKEN";
    }
    Everything works fine except the fact that when I log in with ftp I can't delete the folder or files that are created in the folder.
    I tried deleting the file alone but it wont. I have also tried changing it's attributes but it wont allow me to. I am logged in as account owner so I don't get it.

    The code works great but I just cant delete the folders and files it makes unless I go into the CP filemanager, then I can.

    Any ideas,
    Mike

  2. #2
    JPC Member
    Join Date
    May 2002
    Posts
    20
    Figured it out but leaves more problems.
    Since the code is making the directory, it's owner is nobody.

    This makes it very hard to place each user in there own directory.
    Even in CP filemanager I can only wipe out the directory I first make to hold all user folders and files.

    So unless I change it to ftp to the account to make the account (sending my username and password) I can't get arround it.
    Why make a mkdir() function if you can't pass the owner along with it! GRrrr. There are some other things that can be passed

    bool mkdir ( string pathname [, int mode [, bool recursive [, resource context]]])

    but I can't find out what the 'resource context' is. I assume I could pass a setting here to set the owner?


    Mike
    Last edited by ParksWC; 05-24-2004 at 10:30 AM.

  3. #3
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    mkdir is an OS-level construct that is ported into PHP (this is true for many of the file creation/deletion functions of php such as touch(), unlink(), chmod(), etc.). Therefore PHP can only do what the OS gives it the ability to do.

    By default, if you create a directoory in a Unix-based environment, the directory will be owned by whatever user you were logged in as when you created the directory. Since PHP is running as nobody any files or directories that it creates will be owned by nobody. The only way to change this is to chown the files, and only root is allowed to do that. (BTW, chown() is a PHP function as well, but because only root can use it , it is virtually never used from within PHP.)

    There are two solutions to this problem. One is to use FTP, as you've already touched on. Since PHP is run on the server your password will never be sent off the server, so it is relatively safe to include it in your scripts. If I were doing this, though, I'd create a separate FTP account for the script to use so that I wasn't storing my main password "in the clear" on the server.

    The other option is to use CGI. Most of the servers should be running with suEXEC enabled, which causes CGI scripts to be run under your username instead of nobody. Therefore files that you create via script will also be owned by you. If suEXEC isn't enabled on your server you can use a directory called scgi-bin to run scripts with your username.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

Bookmarks

Posting Permissions

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