how to protect a folder?

Discussion in 'PHP' started by giulio_74, Sep 20, 2013.

  1. #1
    seeking advice to protect a folder ( images and PDF) from the direct download
    tips?
     
    giulio_74, Sep 20, 2013 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Use an .htaccess file in the folder(s) you want to have protected, and add the following:

    <FilesMatch "\.(pdf|jpe?g|png|gif)$">
    Order allow, deny
    Deny from all
    </FilesMatch>

    That will make them inaccessible from direct linking etc, but still available to use from within your scripts
     
    PoPSiCLe, Sep 20, 2013 IP
  3. giulio_74

    giulio_74 Well-Known Member

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    106
    Digital Goods:
    1
    Articles:
    3
    #3
    thank you for answer .
    I had already thought to htaccess ,
    but some hosting do not allow
    then how can you do the other tips?
     
    giulio_74, Sep 20, 2013 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Use another host. Seriously. A host that does not allow .htaccess, or your own setup in any way, is not really worth it.

    Apart from that, there isn't all that many ways to protect certain files from being available - you can of course put them all in a database, and access them from there, but that is a clunky and slow solution.
     
    PoPSiCLe, Sep 20, 2013 IP
  5. giulio_74

    giulio_74 Well-Known Member

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    106
    Digital Goods:
    1
    Articles:
    3
    #5
    thank you for answer
    with a simple script you can not do anything?
     
    giulio_74, Sep 22, 2013 IP
  6. Original Hosting

    Original Hosting Active Member

    Messages:
    203
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    50
    #6
    If you are using cPanel you can do this using Protect Directories.
     
    Original Hosting, Sep 22, 2013 IP
  7. giulio_74

    giulio_74 Well-Known Member

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    106
    Digital Goods:
    1
    Articles:
    3
    #7
    I did not know, however, I need something to code for a client so
    it installs by itself.
     
    giulio_74, Sep 22, 2013 IP
  8. sarahk

    sarahk iTamer Staff

    Messages:
    28,897
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #8
    Then store them below the "root" so that there is not url to them and they have to delivered via a script.

    But if these files have value to you then the cost of decent hosting is worth paying.
     
    sarahk, Sep 22, 2013 IP