Chmod Helo

Discussion in 'PHP' started by Rakaan, Feb 23, 2008.

  1. #1
    Could someone help me with my image uploading script which is uploading files with chmod 600

    Here is the code

    move_uploaded_file($_FILES['attached']['tmp_name'], $att_path."/".$uniq.".".$ext );

    chmod( "$att_path." . basename( $_FILES['attached']['tmp_name']),0644);

    I've added the second line but it doesnt work for some reason and images are still being uploaded as 600.
     
    Rakaan, Feb 23, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Have you tried:

    
    chmod($att_path."/".$uniq.".".$ext, 0755);
    
    PHP:
    Replace 0755 with whatever permissions if you don't like them.

    Jay
     
    jayshah, Feb 24, 2008 IP
  3. NathanH

    NathanH Peon

    Messages:
    39
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am quite sure some hosts don't allow the CHMOD function for security (I may be wrong).
    If worse comes to worse, simply contact your host and have them change the CHMOD on uploaded files.
     
    NathanH, Feb 24, 2008 IP
  4. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #4
    You have to remember user/group permissions. For example:

    A typical cPanel host with user charlie:

    Files created are chown'd and chgrp'd (owned and grouped respectively) charlie.

    However, apache runs as NOBODY, therefore CHMOD function won't work on FTP'd or cPanel created files (nobody can't edit charlie's files unless they are CHMOD 0777). They will only work on files that were created by PHP (file uploads, fopen, etc). If you run with Mod_SUPHP or Mod_PHPSUExec you would not have this problem, as Apache runs as the user, and 0777 permissions are not required for editing and uploads.

    This could be why you are saying this :)

    Jay
     
    jayshah, Feb 24, 2008 IP