We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38441
    • 140 Posts
    (Using Revo 2.2.0 and Articles 1.4.7) I'd like to include an upload button or some way for site visitors who leave a comment on the blog to be able to also include images. I'm exploring the best way to approach this so that images appear in the manager along side comments awaiting approval. I've found BobRays 'FileUpload' snippet but unsure if this is the right approach. Any comments would be great.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I've added the default file manager to Evo's Jot; it involved copying the way an image type TV worked in the Jot template. I don't know how much use that is re Revo and Quip, though.
        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
        • 38441
        • 140 Posts
        Thanks, well i've just tried something you mentioned in an earlier post, by adding the appropriate form fields into the comment template ( navigating to >files tab in manager >Core >Components >Quip >Elements >Chunks >quipaddcomment.chunk.tpl )

        <label for="imageupload">Upload Image:</label>
        <input name="imageupload" id="imageupload" type="file" />


        This works on the page, so great!

        However, where exactly does the image that's just been uploaded go to? (for example, i'd like it to appear in the Manager for Articles under the comments tab, alongside where the corresponding comment appears prior to being approved).

        Oh, and it's just a quick test but i know the chunk should be copied first and then edited but i just wanted to quickly try it out. [ed. note: jaykaye last edited this post 14 years, 1 month ago.]
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          I don't think the file goes anywhere. Files uploaded in a form are stored by the server in a temporary location, and cleared out frequently. A script needs to get the file and move it somewhere. PHP makes a $_FILES array available just as it does $_REQUEST, $_POST and $_GET for dealing with form submissions. http://php.net/manual/en/function.move-uploaded-file.php

          In the case of Quip, I'm not sure if there are events or hooks you can use to add your own processing to move the file wherever you want it. You'll probably have to have a snippet in addition to the Quip snippet to deal with the $_FILES array (if one is present).
          <?php
          // get the uploaded file and move it
          if(!empty($_FILES)) {
              $uploads_dir = '/uploads';
              foreach ($_FILES["pictures"]["error"] as $key => $error) {
              if ($error == UPLOAD_ERR_OK) {
                  $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
                  $name = $_FILES["pictures"]["name"][$key];
                  move_uploaded_file($tmp_name, "$uploads_dir/$name");
              }
          }
          }
          
          
            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