We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 696
    • 46 Posts
    Ok Its quite possible that no1 else will want this but i was having a lot of trouble letting robots see my robots.txt file and google see my sitemap.xml file and more...

    So here is my simple solution for this problem but it can be used for anything...

    if i created a file with the alias robot.txt and called this snippit with a simple [!include!] then it will try and find that file, ok for this porpous you have to set the template to (blank)...

    what if i called the file sitemap.xml but i wan’t to show the contents of sitemap-index.xml then i would call this snippit with [!include? &file=’sitemap-index.xml’!] its that basic... the reson i like it is because it lets be include other files too including php files...

    So here is the snipit its self it really is simple...

    /*
     *	&file 	- if undefined will use PHP_SELF to detect the filename.
     */
     
    if (isset($file)) {
    $file = $file;
    } else {
    $file = $_SERVER['PHP_SELF'];
    }
    
    $include = include($file);
    
    return $include;
      • 4095
      • 372 Posts
      Thanks for this, I think I might have a use for it in the near future. Cheers.
        [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
        Admin Sandbox Login: sandbox Password: castle
        • 16886
        • 40 Posts
        Hi everybody,
        i get an error message if i want to get a html file:

        « PHP Parse Error »

        PHP error debug
        Error: Unknown(): open_basedir restriction in effect. File(/bowlersportal/index.php) is not within the allowed path(s): (/www/htdocs/v155011/:/tmp:/usr/bin:/www/htdocs/v155011:/bin:/usr/local/bin:/usr/share/php)
        Error type/ Nr.: Warning - 2
        File: /www/htdocs/v155011/bowlersportal/manager/includes/document.parser.class.inc.php(705) : eval()’d code
        Line: 11

        [!include?&file=’http://mywebsite/subdir/assets/scores/index.html’!]

        Is there the need the included file has to stored in the same directory where the index.php is stored?
        The included file has:
        JavaScript
        CSS
        Is this the Problem ?

        Thanks
        Lefthanded
          I love ModX!
          • 33337
          • 3,975 Posts
          AFAIK, you need to give the realtive path, for example, your call should look like this:

          [!include?&file=`assets/scores/index.html`!]

          and use Back Ticks, not single quotes! smiley

          Hope this helps.

          regards,

          zi
            Zaigham R - MODX Professional | Skype | Email | Twitter

            Digging the interwebs for #MODX gems and bringing it to you. modx.link
            • 16886
            • 40 Posts
            Thanks Zi,
            but did not work...
            I will try to create a Template for this ...
            Geeting
            LeftHanded
              I love ModX!
              • 22303 MODX Staff
              • 10,725 Posts
              On systems with base_dir restrictions, you must include the full file path on the server, not the relative path or URL. Here’s a slightly different take on this snippet that redirects users to the error page if the file does not exist.

              <?php
              $file= isset ($file)? $modx->config['base_path'] . $file: '';
              if ($file && file_exists($file)) {
                  return include($file);
              }
              $modx->sendErrorPage();
              ?>

              [NOTE: php tags included for syntax highlighting purposes only]

              With this, you can still pass the relative path of the file as a parameter, but it uses the base_path configuration value to give you the full path to the specified file.
                • 16886
                • 40 Posts
                Thank you Jason ,
                but everytime i call the include file, now i get the 404 Page...
                i tried:
                short url like `assets/scores/index.html`
                short url like `./assets/scores/index.html`
                short url like `/assets/scores/index.html`
                full url like `http://mywebsite/subdir/assets/scores/index.html`


                if i call the html file itself, theres no problem but i want to include the output in my normal template...
                  I love ModX!
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Again, you won’t be able to use URL’s, it must be a full physical path on your server. I just tested the snippet, which I named includefile, by creating a file called test.php in my assets/snippets folder, and called it like this:

                  [[includefile? &file=`assets/snippets/test.php`]]


                  Worked like a charm. Make sure your file exists, and if you continue to have trouble, try this code in your snippet to reveal the actual $file value being used:

                  <?php
                  $file= isset ($file)? $modx->config['base_path'] . $file: '';
                  if ($file && file_exists($file)) {
                      $output= include($file);
                  } else {
                      $output= $file;
                  }
                  return $output;
                  //$modx->sendErrorPage();
                  ?>


                  Also, make sure you have template set to (blank) and that the page is not cacheable (or if it is, you care calling the snippet uncached, e.g. [!includefile? &file=`path\foo\bar.ext`!]
                    • 16886
                    • 40 Posts
                    Hi Jason,
                    you solved my problem! Now it works...
                    Thanks a lot for your patience
                    Greetings
                    LeftHanded
                      I love ModX!
                      • 25762
                      • 67 Posts
                      OpenGeek:

                      (You referred me here from another thread)

                      Here is what I have done:

                      1. Uploaded an executable javascript/html file to assets/snippets/empty.html

                      2. Called it from a document with:
                      [[includefile? &file=`assets/snippets/empty.html`!]]
                      (using empty template)

                      What happened:

                      A ’1’ is inserted at the bottom of the source file below the final </html> tag (when the ModX document is view-sourced in browser). The content of the document (e.g., file) displays but the inline styling is totally trashed.

                      When I invoke the uploaded file from the browser URL status line directly (mydomain.com/assets/snippets/empty.html), it displays perfectly.