开发者

Username + password to access images, PHP

开发者 https://www.devze.com 2023-02-13 21:37 出处:网络
I have security cameras which uploads the photos to server. There is no direct access to those folders and I\'m looking for solution where authenticated users can access their photos.

I have security cameras which uploads the photos to server. There is no direct access to those folders and I'm looking for solution where authenticated users can access their photos.

The solution is something like this:

  1. Security camera upload photos to "/home/myserver/[username]"
  2. User 开发者_如何学Gogoes to www.example.com which asks username and password.
  3. Authenticated user have access to the security camera photos.

I have some ideas but I'm asking for typical solutions. Solution should be in PHP.

EDIT: Good answers. I prefer solution which contains easy user management. It should be something for non-technical person. So I can add users using admin account. That was the point of using PHP.


You don't even need PHP for this. You can do it solely by setting up an Apache virtualhost. Basically you could just use Basic Authentication for the authenticating the users and make the directory with the pictures listable.

http://httpd.apache.org/docs/current/mod/mod_auth_basic.html

You should use this in the Directory directive to make the specific directory listable:

Options +Indexes


Put the files in a non-readable location from the internet (outside of the document root). Create a simple PHP based login script, and let PHP list all files which are located outside of the document root (PHP can read those files). If a user clicks the file, open the file with PHP, set the correct HTTP headers and stream it's contents to the browser of the user. Pretty fail-safe.

See fpassthru for a way of streaming the content.


Another easy and high performance option is to use X-SendFile headers (see this module for apache), the functionality is built into Lighty.

Use a simple PHP script to list files in a non web accessible directory. To initiate the download simply set the X-SendFile header to the path of the file and Apache will handle the rest.

E.g.

if($loggedin && file_exists($filepath)) {
    header("X-SendFile: $filepath");
    exit;
}


Why not use htaccess for this in combination with a PHP / web based admin interface like PHPAccess

0

精彩评论

暂无评论...
验证码 换一张
取 消