#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    15
    Rep Power
    0
    I am trying to find a way to change the default file permissions for uploaded files using PHP. When I upload a file using my PHP script the default file permissions are 755. I would like the file to have 744.

    Any ideas?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Washington, USA
    Posts
    52
    Rep Power
    15
    try something like this:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    <?
    if (copy($uploadedfile, "/path/to/$uploadedfile_name")) {
    chmod("/path/to/$uploadedfile_name", 0644);
    } else {
    print('Could not upload file. Check directory permissions.');
    }
    ?>
    [/code]

    [This message has been edited by TDavid (edited November 18, 2000).]
  4. #3
  5. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>I would like the file to have 744


    You mean 644?


    If you set the umask to 022 prior to copying the file, the file (only newly created one, note, the target file being copied treats the same as newly created file) will have 644 permisssion. If you want 646 (-rw-r--rw-), set umask to 020. Check the PHP manual about umask.

    [This message has been edited by freebsd (edited November 19, 2000).]
  6. #4
  7. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    15
    Rep Power
    0
    Another question along this line is, If I have a directory setup so that people can upload pictures into it, What chmod setting is the best to set for files being uploaded so that people can view the pictures, but not be able to execute files. Is that even a possibility? I am concerned that someone might be able to upload an executable and then run it to delete everything or something like that.

    I know that I can progam code to only allow .jpg files for example, but I have not gotten that advanced yet.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    7
    Rep Power
    0
    hey there,
    try this.....

    string filetype (string filename)

    Returns the type of the file. Possible values are fifo, char, dir, block, link, file, and unknown.

    Returns false if an error occurs.

    or:

    $ext = strrchr($filename,'.');
    It will return the extension with the . on it (ex: ".jpg")

    hope that gives you some ideas
    ccbcreg

    I know that I can progam code to only allow .jpg files for example, but I have not gotten that advanced yet.


IMN logo majestic logo threadwatch logo seochat tools logo