We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1511
    • 144 Posts
    I’m currently using NewsPublisher to add blog posts to my site. I would also like to be able to upload a file through a form.
    The same way as the post is inserted into the database, I would like to process the uploaded file and save it to a certain folder.

    Are there any API functions to handle such things or do I have to take care of everything myself?
      • 26471
      • 17 Posts
      Will the FileUpload snippet do what you want? It uploads files to a given directory.
        • 1511
        • 144 Posts
        Sorry for a late answer, but, thank you, I’ve written a sort of FileUpload for managing pictures, creating thumbs, setting TVs and so on.
        The FileUpload snippet helped a bit. smiley
          • 21841
          • 36 Posts
          how about making it available ? huh

          I need something similar, but do not want to re-invent the wheel.

          OK, I’m lazy really ! laugh

          NWJ
            • 25663 MODX Staff
            • 12,272 Posts
            Actually that would be a wonderful addition to the NewPublisher which hasn’t seen an update in quite a long time. How about poking and prodding around in it and posting the code back here so we can vet it an release it as the next release?
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 1511
              • 144 Posts
              Well, I needed a quick fix for being able to link a picture to a document via a TV and simultaneously create a thumbnail when uploading the pic.
              The code is still a mess but I can adjust it a bit and then post it.

              For those interested, the whole cycle looks like this:

              I have a list of articles, each article has one or no pictures.
              The image filename is stored in a TV of the Image type.
              I have a folder on server which contains images I’d like to use as "news pictures".
              When listing the articles I show their thumbnail.
              When showing the article I display the original image.

              The article adding form has a select input field which lists all the pictures in a specified folder.
              Once you select one, there’s an instant preview available.
              In you’d like to upload a new picture, an input field for that is available too.

              Once you upload the picture, the snippet creates a thumbnail, saves it on the server, saves the uploaded picture, sets the TV containing the image filename.

              If you edit the article in manager, you can easily select another pic from anywhere on your server via resource browser.

              When I list the articles on the web page a snippet checks if the thumbnail exists, otherwise it is recreated on the fly.

              And that’s it. For now.
              Next step is to integrate the procedure into eForm for better error handling (well, now there isn’t any laugh). I’ll get back when I’ve finished it.