We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21258
    • 14 Posts
    I have a situation where web users are able to upload documents to a folder located 1 level up from the website root directory. The documents contain personal information so I figured this was the best way to keep them secure.

    Manager users are the only ones that should be able to download these documents so I have set the File Manager path to this folder and everything seems to work well except that the download link in the File Manager will not reference outside the website root. I am having trouble getting my head around how to do this and was hoping someone may have already managed to get this working, has any tips for me, or maybe a better solution... ?
      • 21496
      • 225 Posts
      What speaks against simply creating a folder under the root directory and protect it with .htaccess, so it cannot be accessed via browser?
        René
        • 21258
        • 14 Posts
        Quote from: nightsignals at Sep 26, 2007, 07:36 PM

        What speaks against simply creating a folder under the root directory and protect it with .htaccess, so it cannot be accessed via browser?

        Thanks for your reply.

        The web user uploads the documents from the browser into the folder so there will need to be browser access.

        Are you meaning that the folder be password protected using an .htaccess file and then use a php script to store the password and allow access when someone needs to upload?
          • 21496
          • 225 Posts
          Quote from: netpuppy at Sep 26, 2007, 09:48 PM

          The web user uploads the documents from the browser into the folder so there will need to be browser access.

          Well, I don’t get this. If that folder is above the document root, how can it be accessed with the browser? Don’t you use a script for the upload and then moving the file into that folder? If so, you can just move it to a different folder under the document root. Since this happens on the server, .htaccess wont interfere with this. Or am I overlooking something ...? huh
            René
            • 21258
            • 14 Posts
            Okay, I’ll have to have a look into this as I have not used .htaccess to stop browser access before. I am sure you are not overlooking anything.

            Thanks for your input, I appreciate it.
              • 21258
              • 14 Posts
              Quote from: nightsignals at Sep 26, 2007, 07:36 PM

              What speaks against simply creating a folder under the root directory and protect it with .htaccess, so it cannot be accessed via browser?

              Maybe I am missing something... how is the File Manager going to access this folder if it not accessible from the browser?
                • 21496
                • 225 Posts
                I guess we need to clarify first what we mean by access with the browser. To me, access with the browser means you have a link like www.yourdomain.com/uploaddir/ where people see the content of that directory.

                When using the MODx Manager, of course you’re using the browser too. But the file manager is showing the content of the directories by reading it with php. That’s why .htaccess cannot prevent that listing, and you even see the .htaccess files in the file manager, while by access with the browser, the .htaccess file is never visible.

                I think I need to understand better now how your web users are uploading those files? I was assuming your web users don’t have access to the MODx Manager, and the file upload for them happens with a plugin or snippet you give them to use?
                  René
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  In any case, a file upload via HTTP (through the browser) is always stored in a temporary location with a temporary name. The meta data for the file is available to PHP as the $_FILES[] array, and the file has to be moved to a permanent location, at which point the temporary file (usually in /tmp, not the absolute URL / but the root filesystem /, on a *nix server) is deleted. So the browser is not uploading the file to its final location, and the temporary file is not accessible to the browser at all. Your processing script can move the file to any location that is accessible to PHP, whether in your webspace or not.

                  http://il2.php.net/features.file-upload
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 21258
                    • 14 Posts
                    Sorry for the confusion I have created here embarrassed

                    I do not have a problem in getting the files uploading to the folder outside of the root directory (or inside) by the web users. I managed to find a php script that did this for me perfectly. My trouble has been with getting these files downloaded again from within the File Manager.

                    It may pay to mention at this point that I am not a php or modx guru and I have just become confused when trying to figure out how to modify the File Manager to reach above the root to grab the uploaded files.

                    I have found the place within the Manager section where the File Manager download link is located and it appears to just be a standard html anchor reference. I have also searched out a number of php scripts that offer solutions to my problem however trying to integrate these into the file manager has my head spinning as I am still trying to understand exactly what is going on in the files.dynamic.php file. I notice that the other functions within this file seem to be using scripts to carry out their tasks, would making the download a script function be a good idea as well (as a permanent feature) to allow the File Manager download to function irrespective of the folder location?

                    Thanks again for trying to help a confused new user.
                      • 21496
                      • 225 Posts
                      I’m still not sure if I hear you correctly, but it seems what you want is to allow manager users to download those confidential files the web users did upload, and at the same time hiding those file from web users.

                      As you’ve found out, in order for manager users to be able to download those files, they have to reside under the document root, or there will be no download link to them.

                      My solution still is:

                      a.) storing those files in a directory under the root, so the manager users will get their download link (it seems you know how to upload the files to any folder, so just chose an appropriate one)

                      b.) protecting that folder from the web users with .htaccess, so they are only visible in the file manager for the manager users, but not for the web users, as they have no access to the manager and therefore also no access to the file manager.

                      Is there any reason this is not working for you?
                        René