SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Change file permissions on Upload?

    Hi,

    I'm using the following code(just a snippet of a larger script) to upload files to my server.

    PHP Code:
    $uniq  gmdate'dmYHis' ) . '_' md5_file$_FILES['file']['tmp_name'] ) . $ext;
                          if ( 
    move_uploaded_file$_FILES['file']['tmp_name'], realpath'../wdocs' ) . '/' $uniq ) ) {
                              
    $ipdf $uniq;
                          } else {
                              
    $ipdf $row['cvfile'];
                          } 
    However, when I log in to the FTP, I can't download the files that have been uploaded.

    Is there a way to set the file permissions to CHMOD 777 on upload?


    Many thanks

  2. #2
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by invision2 View Post
    Hi,

    I'm using the following code(just a snippet of a larger script) to upload files to my server.

    PHP Code:
    $uniq  gmdate'dmYHis' ) . '_' md5_file$_FILES['file']['tmp_name'] ) . $ext;
                          if ( 
    move_uploaded_file$_FILES['file']['tmp_name'], realpath'../wdocs' ) . '/' $uniq ) ) {
                              
    $ipdf $uniq;
                          } else {
                              
    $ipdf $row['cvfile'];
                          } 

    However, when I log in to the FTP, I can't download the files that have been uploaded.

    Is there a way to set the file permissions to CHMOD 777 on upload?


    Many thanks
    check out the link:
    http://php.net/chmod.
    Additionally you can look at this also:
    http://php.net/umask

  3. #3
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure, there is ol'good chmod() function in php
    do not set it to 0777 tho. 0666 is ok and safe for files

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    edit: ninja'd

    http://www.php.net/manual/en/function.chmod.php

    not sure that's the problem tho, what's the error from the ftp client?

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, great response fellas

    So with my code, would it be like this:

    PHP Code:
    $uniq  gmdate'dmYHis' ) . '_' md5_file$_FILES['file']['tmp_name'] ) . $ext;

    if ( 
    move_uploaded_file$_FILES['file']['tmp_name'], realpath'../wdocs' ) . '/' $uniq ) ) {

    chmod("../wdocs/$uniq"0666);

    $ipdf $uniq;

    } else {

    $ipdf $row['cvfile'];



  6. #6
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hash, it is very common problem.
    web servers often run with privileges of user nobody. so, if file was created by web server, it belongs to nobody
    need "read by all" permission to read this file with ftp

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Shrapnel, can you confirm if my most recent post code is suitable for adding file permissions to the uploaded file?

    Thanks again

  8. #8
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure. especially if it works as desired

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2008
    Location
    United Kingdom
    Posts
    1,285
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oooooh. Like a glove!

    Thanks for the help guys


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
  •