PHP - Solution - File Password Protect

561 views Asked by At

So, I have a client requesting a solution to password protect files. He wants to basically have a solution similar to OpenDocMan. However he showed me something from another client that basically just password protects the file itself no user name. So he can upload files, put a password on that file, send links directly to that file and then when users click on a link they are prompted with the password and then the clients puts it in and the file is released. Anyone know of a solution that can do this exact requirement?

2

There are 2 answers

2
Patrick On BEST ANSWER

You can setup a basic validation page so that when a user visits a page they enter the document id (or it's encoded in the link) and you put up a simple form with a password field and a submit button.

If the password matches what is stored in the database for that document id. send that file to the user.

Keep the uploaded files outside the /web directory so you don't have to worry about people hacking the system by guessing filenames.

The files themselves won't have passwords on them, but the only way from the outside to get the file is to have the password.

1
James Miller On

If you don't have to have a unique password for every file, you can try apache's mod_auth. You drop a .htaccess & .htpasswd file in the directory you want to protected, and update the users/passwords in the .htpasswd file.

If you want something more dynamic, try mod_auth_mysql, so you have better control from your application.