hi,
in my site the users can upload pictures, and the files are correctly placed in /assets/uploads
i noticed that, knowing the file name, anyone typing the url http://mysite/assets/uploads/guessfilename the browser is allowed to see it, while the uploaded file is intended to be seen only by the same user that uploaded it.
what is the best way to accomplish this in your opinion?
thanks in advance
-
☆ A M B ☆
- 3,141 Posts
If you want to make sure there is no way a file name can be guessed, you'll have to store them outside the webroot. But then to show them, you would need to add some sort of controller that checks if the user is supposed to be able of viewing it or not, and only if that is allowed show the image.
A slightly easier way would be to rename file names to a random hash on upload. That will make guessing the filename a whole lot harder, but not impossible.
-
☆ A M B ☆
- 24,524 Posts
You can use Static Resources to represent the files. With a bit of fiddling you can even use a Media Source with the static resource; basically you need to have some method of prepending the Media Source's base path to the path of the file in the Static Resource. You can even upload a file while selecting the path from the drop-down while editing the Static Resource. You get the MODx file browser; select your Media Source, and select or upload and select files. It can get interesting if you need to upload large files, you need to make sure that your web server, your PHP configuration and the MODx system settings allow the upload of such large files.
Right now I use a chunk with the same path as the Media Source's base path, [[$pathPrefix]]secure/images/image.png, so that I can edit the chunk if I ever change the base path of the Media Source, rather than saving the full path to the database. MODx will oblige by processing the chunk to result in the full path.
I'm working on a plugin to automatically fetch the base path of a given Media Source, taken from a TV, and re-write the static resource's path at run-time.