Jump to content

Block access to files


jdp407

Recommended Posts

I am setting up a system that requires certain files (pdfs, docxs, etc) to only be able to be viewed if a certain cookie is set.  If I were doing this with a PHP file, I could do it very easily, however as this is not the case, I have no idea how to go about performing this task.  I believe MIME types come in somewhere...

 

For example, if we take this source forge link http://sourceforge.net/projects/jaycalculator/files/Win32/JayCalc 0.2.0.exe/

It appears to be a .exe file, however the web browser is able to display it as a html document.

Link to comment
https://forums.phpfreaks.com/topic/202750-block-access-to-files/
Share on other sites

That link is NOT a link to the actual file. It is a link to a page where you can download the file. The backslash at the end indicates that the "JayCalc 0.2.0.exe" is a folder name not a file name. They may also be using modrewrite functionality to reformat the url into parameters - but that is not needed for what you want.

 

First off, put the files into a filder that is NOT web accessible. Then simply build a front end to determine the user's level of access to the files. If the user is allowed, provide them a link to a download page - adding a unique identifier for the file. Example:

<a href-"downloadfile.php?fileid=123">Download this file</a>

 

That page should again check the user's permission to the file. Then user server-side code to READ the file and then serve to the user's browser. To see how to do this, just do some searching for force download scripts.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.