jdp407 Posted May 24, 2010 Share Posted May 24, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/202750-block-access-to-files/ Share on other sites More sharing options...
Psycho Posted May 24, 2010 Share Posted May 24, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/202750-block-access-to-files/#findComment-1062637 Share on other sites More sharing options...
jdp407 Posted May 24, 2010 Author Share Posted May 24, 2010 Thank-you very much! Quote Link to comment https://forums.phpfreaks.com/topic/202750-block-access-to-files/#findComment-1062650 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.