protecting files uploaded thru a php script

Discussion in 'PHP' started by krishmk, Jul 15, 2009.

  1. #1
    I am trying to allow job seekers to upload their resume to my site.
    The uploading process is handled thru a php script and the file(resume) is stored in a directory in my web server.

    How do I protect these uploaded files?
    I mean I dont want anyone to see the files without permission (direct access thru url)

    example: mysite.com/uploads/resume1.doc

    ----------------------------------------------

    If I password protect this folder thru the option provided in cpanel, could I still access this folder thru my php script (when recruiters/ admin want to view/download the resumes)?
     
    krishmk, Jul 15, 2009 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Best bet is to store the file outside the root directory so that they are inherently inaccessible from any url.

    Basically you're root directory is: /home/mysite/public_html

    Store them in: /home/mysite/uploads

    You would then read and output the file to the user after they have been authenticated. You can use file_get_contents to get the file, and echo it using the appropriate headers for the file type.
     
    jestep, Jul 15, 2009 IP
  3. goscript

    goscript Prominent Member

    Messages:
    2,753
    Likes Received:
    306
    Best Answers:
    0
    Trophy Points:
    315
    #3
    Or you can password protect the folder keeping the files allowing access only by the script.
     
    goscript, Jul 15, 2009 IP
  4. JefK

    JefK Member

    Messages:
    66
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    45
    #4
    If you want to deny direct access to the file, you can upload the files in upper level of public_html, in this case you should use fread() command rather than file_get_contents to provide the file to allowed users.
     
    JefK, Jul 18, 2009 IP
  5. neegeris

    neegeris Banned

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    .htaccess->

    denny from all
    allow from IP
     
    neegeris, Jul 18, 2009 IP