I'm doing a website where people can upload files. Files can be in public access, or private access. To avoid encoding problem, I store files with a random name in an "hidden" directory. However, the public folder can be accessed directly if we know the url. (That's not a problem).
My public part is OK, my php script give the user an url looking like that:
http://example.com/d/1/524dd711c3102/b1bi.png
And apache control the access with :
RewriteRule ^d/(\d+)/([a-zA-Z0-9]+)/(.+)$ ./files/public/$1/$2 [L]
So far, it's all good.
But now, the tricky part is with the private files. I need that only the user who uploaded the file can access the file. And I want to avoid PHP-based solution with some readfile or file_get_contents
or things like this.
In fact, I would imagine something like :
The user try to access ./files/private/< folder_id>/< file_id>
and Apache "ask" a PHP file if it's OK or not.
And the problem is, I'm don't think it's possible.
So :
- Is it possible? if so, how?
- Can you think to a better solution? (I thought to use the standard Apache/http authentication but it would be tricky to restrict access per users.
(I could also use XSendFile, but I want the user to be able to read/watch the file on the website without downloading it (For a picture for example))
Thanks :)