SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    File permissions problem..

    Hello there!

    I have been trying to give permissions to my uploaded files. The problem is I can't view the images I upload.

    I have a directory.. uploads/file(number)/image

    I click on uploads folder and file permissions and 7 5 5 execute and read to all!

    Even if i check these permissions on uploads folder, that permissions don't go beneath folders = file(number)/image.

    If I click an image and set file permissions then I can't view the image but that's not the idea as you can approve..

    Files and images under uploads folder must be all check as read and execute.. But that s my problem..

    How can I check all under (uploads) files as read/execute?

    Thanks a lot in advance!!!

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi hal7,

    Welcome to the SitePoint forums!

    You need to determine what users Apache is running under. Sometimes this is root (often represented by 0) or sometimes this is another user like www. If the user that your granting permissions to is different than the Apache user then it does not matter what permission you give the web-server will still not have rights.

    Regards,
    Steve
    ictus==""

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    hal7,

    Welcome to SitePoint!

    To give further explanation to Steve's, the permissions are given in a matrix with values: Read (4), Write (2) and Execute (1). These are obviously binary so their addition can designate the permissions granted to: Owner, Group and Guest.

    As a rule of thumb, you NEVER want to grant anyone but yourself Write permission so either a 4 (in general) or 5 (only allow PHP scripts to be executable ... and they generally don't even require that designation. Thus, 644 or 755 are common - unless you want to bar visitors from viewing in which case 600 would be what you would use. Just remember NEVER to give yourself a non-write code or you'll have difficulty resetting that without cPanel's File Manager (or the like).

    When you set a directory with the 644 (or 755), that will be assigned to any file added so that's likely the problem you're running into.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  4. #4
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! I will definitely learn a lot on this forum!

    I think I kind of understood what you guys try to explain.. Maybe I should give more information about the problem..

    My system is adding adds to website. This adds are added in a file in "uploads folder. and An image of the add is added in the folder of an add in uploads folder:

    uploads/add1/image1.jpg

    My problem is: I click on uploads folder and I give the permission: 755 read to all and execute to all. And apply this to all below files.

    When the user creates a new add (so a new add file) that file doesn't get that 755 permission.

    New created file gets 744 as default and so you can't view the image...

    What do I have to do so that a new created file get 755 permission as default?

    Thank you very much for your time!

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    hal7,

    First, did you change the permissions on the adds folder to 766 as suggested? It MUST have write permission for the (Apache) user.

    Okay, saying that, I'm more concerned about what you didn't say: That you confirm that the file was uploaded (to the server's upload directory) then READ by imagecreatefromjpeg, resized and then written to your adds folder. This will ensure that the uploaded image was uploaded and was a JPG file with the additional benefit of ensuring that it is an appropriate size.

    If you're not checking the upload files in this manner, you're inviting hackers to deposit "payloads" on your server to spread across the Internet.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I did change the the permission of the uploaded adds then I do not get problem with viewing images!
    Because the permission is changed to readable.

    I cannot view images unless I don't change the permission of an add manually!

    So problem is the adds get permission as unreadable as default.

    and what you are concerned is unnecessary because I have set all the security checks in my php code. (Like check size and format of the file)

    Plus I ve asked this problem to my hosting company they can't solve it either:s

    I am desperate!

  7. #7
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way,

    I have .httaccess(Options -Indexes ) file in uploads folder. Do I have to change it or something maybe?

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    hal,

    That seems to be an unusual setup on your server. If this is hosted, ask your support team for help as new files should receive the same permission as the folder. Perhaps using PHP to change the file permission after storing in the folder?

    Unnecessary? Ha! Any script kiddie can hide a "payload" in an image file and the file type will report the appropriate image definition. THAT is why I recreate any image uploaded to my server. I may be paranoid but there are script kiddies out there looking for kicks and I don't want to be a willing target.

    First, the filename is .htaccess (not two t's - presumably a typo) then Options -Indexes merely forbids Apache from providing a directory listing so it has nothing to do with this problem.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey dklynn,

    Thanks voor the answer. I have passed the problem to my host but they couldn't figure it out yet :s

    What kind of php code you can tip to change file permission?

    Sorry I didn't mean like it is not important with unnecessary but I meant I have done all those things you are concerned about.

    I hope I will be able to solve this problem soon ..

    Thanks alot!

    Hal

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    hal,

    Go to www.php.net/chmod for:

    Quote Originally Posted by www.php.net
    bool chmod ( string $filename , int $mode )

    Attempts to change the mode of the specified file to that given in mode.
    Yes, they've got plenty of examples, too.

    BTW, IMHO php.net has the best documentation anywhere so bookmark your local version and learn to guess the function you're looking for.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  11. #11
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks DK!

    I ll be on it!

  12. #12
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by dklynn View Post
    hal,

    Go to www.php.net/chmod for:



    Yes, they've got plenty of examples, too.

    BTW, IMHO php.net has the best documentation anywhere so bookmark your local version and learn to guess the function you're looking for.

    Regards,

    DK
    Cool DK,

    I've used these commands in Linux a very long time, however I never thought to see if PHP had commands for these. Well you learn something new most days, so thank you.

    Regards,
    Steve
    ictus==""

  13. #13
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Steve,

    Glad to help!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •