We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28033
    • 925 Posts
    On my website, I allow users to submit walthroughs/etc. for various games. I need a "wrapper" ala what GameFAQ’s shows when you look at the guides on that site (has the author info, etc.).

    My previous snippet was used to output a chunk --- but that was inside MODx. This will be based outside MODx.

    All I’m really needing is the PHP function to grab the .txt file from the server, and if there’s any way to add part of the URL before it (so some script kiddie can’t insert in a random URL to output the data). Like I would have symphonicheaven.com/guides/ before the placeholder for the filename, and the URL would include the text walkthroughs/lolthisisatextfile.txt.

    BTW, would this approach make the text file like a HTML file, and "push" all the text next to each other, or would it output it as if I was viewing it as a regular .txt file?
      My Snippets
      -> PopUpChunk v1.0
      • 3749
      • 24,544 Posts
      If you wrap it in <pre> Your stuff </pre> tags, the lines and indentation will be preserved.

      You’ll want to sanitize it with htmlentities() to prevent injection:
      It will look something like this:

      <?php
          $text = file_get_contents ($filename);
          $output='<div class="fileOutput">';  // so you can style it
          $output .= '<pre>';
          $output .= htmlentities($text, ENT_QUOTES);
          $output .='</pre>';
          $output .='</div>';
          return $output;
      ?>


      Bob

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        You could just add the class to the <pre> tag, <pre class="fileOutput"> and skip the extra set of <div>...</div> tags.
          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
          • 28033
          • 925 Posts
          Ooh, that’s just what I needed (I saw like 10 different ways to include files when I did a couple search, so I kinda got confused on what to use tongue).

          Thanks so much. grin
            My Snippets
            -> PopUpChunk v1.0