简体   繁体   中英

how to protect images inside upload folder from viewing by anyone EXCEPT admin

Ok, desired (probably impossible?) scenario is next:

1) anyone can upload image(s) to folder

2) only admin, via web admin interface/regular, password protected admin panel can see it

I guess it is impossible, unless i store images to database directly (as BLOB type), and show them inside admin panel (which will decrease performance, i guess).

So, what i could do, a) except to place blank index file in upload folder (already done) but i guess there are ways to guess/get names of files

b) and maybe, add some .htaccess protection (what would be your advice?)

Again, uploading is a part of form (there is no registration required!), i need some way to allow only admin to see/download images, but to protect it from others, because sensitive data are in question.

Here you go:

1) Do not store files in your DB. Ever.

2) Protect the upload directory (where ONLY uploaded files will live) with an .htaccess - "deny all" (basically) -- or store the upload directory somewhere NOT public to the web (see #3, below)

3) Have an interim file that serves file downloads (is user logged in? If so, set headers and readfile() the actual file - this will force the file to download. The database should store the file name, path, and other relevant details)

The PHP upload script can save files in any directory, even the one with the .htaccess in it.

Once the form is submitted, you can do ANYTHING you want with the files uploaded.

Why don't you store the images in a folder that is simply not accessible from the web, and then programmatically provide access to those files from the admin interface?

您可以在上传后使用管理员的公钥加密图像,因此只有管理员的私钥才能解密和查看。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM