How to change File permission settings for PHP

Discussion in 'PHP' started by krishmk, Aug 10, 2011.

  1. #1
    I am on an unmanaged Dedicated server and here is the problem.
    I have a folder named "uploads" where images are stored. I have coded a PHP script that stores the files here.

    PHP is able to write to this directory only with "777" permission. File writing does not work with 755 or 775 permission on this server.

    I know allowing "777" invites security issues. So how to allow PHP write files with "755" permission.
    I have SSH access and can modify the apache/php configuration files if required.
     
    krishmk, Aug 10, 2011 IP
  2. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #2
    I wouldn't worry about changing the file permissions. You need to change the owner that the directory belongs to. I'm pretty sure it should be whatever the owner name on your server is for apache, but I could be wrong. If you change it appropriately then you will be able to leave it at 755 and still allow your script to write to the directory.
     
    Thorlax402, Aug 10, 2011 IP
  3. ausrixy

    ausrixy Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #3
    you should be able to do this with a good ftp program.
     
    ausrixy, Aug 10, 2011 IP
  4. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #4
    Pretty sure he's looking to be able to upload images from the website itself. Possibly an image hosting site?
     
    Thorlax402, Aug 10, 2011 IP
  5. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #5
    maybe when you upload change the permission to 777 then after the upload process change it back to 755..

    you can use the chmod function for this one..
     
    JohnnySchultz, Aug 11, 2011 IP
  6. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #6
    Not sure if that would work. Usually executing a chmod command won't allow the user to give permissions that they themselves don't have. In this case, if the permissions are 755 and he is not the file owner then he will not be able to change the permissions to 777.
     
    Thorlax402, Aug 11, 2011 IP
  7. krishmk

    krishmk Well-Known Member

    Messages:
    1,376
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    185
    #7
    Well its a custom site wherein our site members can upload avatar for their Profile Page. We store avatars submitted by the Members in "uploads" folder.
    Looks like I need to change the owner for that particular directory as suggested by the other member here. Will need to find out how to do this.
     
    krishmk, Aug 12, 2011 IP