We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4266
    • 70 Posts
    How to make TV with upload field to attach files?

    For example:
    There is a product catalogue. You need to create page for every product and to attache pdf-manual on each page.

    As I understand I need to create TV with "file" input type. But what to do next I have no idea sad
    • The simplest thing would just be to put a link on the page to the location of the file. Browsers will automatically go into "download" mode, or display the .pdf file in a browser plugin, depending on how the user has his browser configured.

      <a href="assets/files/product1.pdf">Document</a>

      Upload your .pdf files using the Manage Files section of the MODx Manager, or an ftp client.
        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
        • 22097
        • 37 Posts
        If the page you created has the TV of type file, you should be able to include that in the contents area of that page.

        for instance. If your TV has the name AttachedFile, you should incorporate the tag [*AttachedFile*] somewhere on the page. Make sure you choose Hyperlink as the widget type for the TV.
          • 4266
          • 70 Posts
          Quote from: Olaf at Oct 04, 2005, 07:04 PM

          If your TV has the name AttachedFile, you should incorporate the tag [*AttachedFile*] somewhere on the page. Make sure you choose Hyperlink as the widget type for the TV.

          Thank you, OIaf.

          But there are some problems with such approach:
          1. The link is always displaying on page, even there is no attached file;
          2. You need to create new TV for each new download link and insert it in template;
          3. You can’t write the custom link-text when editing page (it predefined in TV settings);
          • You can create a TV [*link*] with a "text" input, leave the values blank, use a hyperlink widget, and set the display text to what you want the linked text to be, maybe something like "Product Documentation (PDF)". Put the TV [*link*] in the document content where you want it and edit the URL.

            Every link will have the same linked text, but that’s not such a bad thing, it makes for consistancy for the user.
              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
              • 22097
              • 37 Posts
              There are indeed some problems with this standard method. But that is where the power of MODx could help you out. But that would mean writing a snippet. As always the basic functionality is limited, and more advanced features require some work.
              • So what is wanted here? The ability to specify a link AND upload the file all at the same time? That would definitely take a snippet, and security checks, logins, folder permission checks, a world-writable folder, etc.

                I don’t see the benefit over logging in to the Manager and uploading the pdf file using File manager; although uploading a whole folder full of pdf files with an ftp client would be even better, since the folder for the .pdf files wouldn’t have to be world-writable. That’s a big security hole, especially in a shared hosting situation.

                It’s a pity PHP’s ftp functions are so limited. Downloading via http is OK, but http really isn’t designed to transfer files. That’s why it’s called HyperText Transfer Protocol, and ftp is called File Transfer Protocol. Sure, I’ve used a table knife as a screwdriver, a scraper, a punch and a hammer, but it’s much better to use the proper tools. So allow the public download via HTTP hyperlinks, but upload the files to secure folders with ftp.

                  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
                  • 4266
                  • 70 Posts
                  Thank you all for discussion.

                  I’ve decided to use just FCKEditor to insert download link on page.
                  It’s really simple and comfortable smiley:

                  1. Type link text and select it;
                  2. Choose "Insert hyperlink" icon in FCKEditor toolbar;
                  3. Push "Browse server" button and choose needed file or download it using upload field.
                  • Always best to try to avoid re-inventing the wheel wink
                      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