Link to home
Start Free TrialLog in
Avatar of sam15
sam15

asked on

Protect_fiile

If i have a public directory on Apache with a few public files.
is it possible to add one file and protect it using userid/password or password only.
How can i do this

Is it possible also to upload it to a database table and have a link to it that opens it like a file system. That would require more code though.
Avatar of a1aait
a1aait
Flag of United States of America image

You can restrict access to a file by using an .htaccess file in its directory.  You will need to point it to a password file, best kept in a different, non-public directory. (or an authentication server)
Here is a decent description:
http://www.euronet.nl/~arnow/htpasswd/documentation.html

As for uploading an image to a database and retrieving it as a file:  You can do this with MySQL and PHP.
Here is the basic way to it:
http://www.wellho.net/solutions/php-example-php-form-image-upload-store-in-mysql-database-retreive.html

Avatar of sam15
sam15

ASKER

so you can restrict access to a file in a specific directory or create a protected diretory and limit access to it?

Do you have to mess up with the main .htaccess and .paswrd files or you create a second copy and place it in this directory.
ASKER CERTIFIED SOLUTION
Avatar of a1aait
a1aait
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sam15

ASKER

great one last question

can I have one userid/password for ALL users or one userid/password for everyone. Does apache allow you to configure both.
You can make one or many userid/passwords.  The example only requires a "valid-user" which just means they exist in the .htpasswd file.    Another option is to just use one userid, but change the pw now and again and only send the new password to those who should have it currently.  You can't really track who is doing what this way.