mkdir permissions problem

Discussion in 'PHP' started by olli460, Feb 19, 2009.

  1. #1
    Hello,

    Ive got an image upload script and im trying to make it so when i upload an image it checks if the game folder already exists, if it dosen't i want it make a folder with the game name and put the image into that folder.

    I had it working fine without the making the directory, but ive added this bit of code

       
     if (!file_exists("../images/games/$game_name/")) {
          //make the directroy
          mkdir("../images/games/$game_name/", 0777);
        }
    
    PHP:
    And its now making a directory but any images that go into that folder get given the wrong permissions and i lose ownership so i cannot edit the image any way.

    If i go into my directory admin and click "Reset Ownership" it then lets me delete/rename the image and its permission attributes.

    How can i get it so when the image is uploaded into the folder created by the mkdir function it gives the permissions to me so i can delete/rename it whenever i want too.

    Thanks in advance
    Olli460
     
    olli460, Feb 19, 2009 IP
  2. DanielHB

    DanielHB Active Member

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #2
    You should be able to use chown to give yourself ownership of the directory and then if you need to use chmod to change the permissions.

    Both are available from PHP although using them would depend on how the server is setup.
     
    DanielHB, Feb 19, 2009 IP
  3. olli460

    olli460 Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hello, Ive tried using chown but it dosen't seem to do anything. What would need changing in the server for this to work?

    Regards
     
    olli460, Feb 19, 2009 IP
  4. DanielHB

    DanielHB Active Member

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    71
    #4
    How is PHP set up on the server? If I remember correctly, if it's an Apache module the owner is set as Apache.
     
    DanielHB, Feb 19, 2009 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Only root can run chown, and Apache is almost never running as root. So unless olli460 is running his own dedicated server or VPS, even thinking about chown is a waste of time.

    Check umask to make sure that it's 0, otherwise you may find that directories are not being created with the permissions you intended.
     
    SmallPotatoes, Feb 19, 2009 IP
  6. olli460

    olli460 Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hello,

    PHP Was just setup as defualt when Direct Admin was installed using CLI.

    I am running a dedicated server, Ive made a cron job which changes the ownership of the folders every 5 minutes, It seems to be working for now but its not an ideal solution so if anyone has anymore ideas then let me know.
     
    olli460, Feb 22, 2009 IP
  7. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #7
    umask, umask, umask.
     
    SmallPotatoes, Feb 22, 2009 IP