List

Try: ca/tecreations/ViewFile.php -- Online


<?php
    require_once $_SERVER['DOCUMENT_ROOT'] . "/Base.php";

    function getFileText($path = "") {
        if (empty($path)) {
            die("Path cannot be set to empty."); // unauthorized or programming error
        }
        $text = file_get_contents($path);
        return $text;
    }        

    global $PREFIX_DIR;
    require_once $_SERVER['DOCUMENT_ROOT'] . "$PREFIX_DIR/Secure.php";

    GLOBAL $DOCROOT, $db;
    //$db->setDebug(true); 

    GLOBAL $path;
    if (isset($_REQUEST['path'])) {
        if (!empty($_REQUEST['path'])) {
            $path = $_REQUEST['path'];
        }
    }

    GLOBAL $text, $error_msg;
    if (!empty($path)) {
        if (strpos($path,"..") !== false ) {
            $error_msg = "Cannot go to higher level directory. Specify a subpath and filename.";
        } else {
            $text = htmlentities(getFileText("/var/www/tecreations.ca/html/" . $path),ENT_QUOTES|ENT_HTML401);
        }
    }
    require_once $DOCROOT . "$PREFIX_DIR/start_html.php";
?>
    <!-- @see start_html.php    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> -->
    <style>
    div.padded {
        padding-top: 25px; 
        padding-right: 25px;
        padding-bottom: 35px; 
        padding-left: 25px;
    }
    </style>
</head>
<body>
<?php 
    include_once $DOCROOT . "$PREFIX_DIR/header_start.php";
    include_once $DOCROOT . "$PREFIX_DIR/menu/userMenu.php";
    include_once $DOCROOT . "$PREFIX_DIR/menu/contact.php";
    include_once $DOCROOT . "$PREFIX_DIR/header_finish.php";

    GLOBAL $error_msg;
    if (!empty($error_msg)) {
        print("<p>&nbsp;</p>");
        print("<p><span class='red'>$error_msg</span></p>\n");
        print("<p>&nbsp;</p>");
    }
?>
<p><a href="/ca/tecreations/List.php">List</a></p>
<p>Try: ca/tecreations/ViewFile.php</p>
<div class="padded jumbotron">
    <form name="" id="" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET"><!-- for instructional purposes... -->
        <label for="path">Enter a path without a preceding slash:</label>
        <input type="text" name="path" id="path" value="<?php 
                                                            GLOBAL $path;
                                                            if (empty($path)) {
                                                                print("Path to file on https://tecreations.ca/");
                                                            } else {
                                                                print($path);
                                                            }
                                                        ?>" onfocus="document.getElementById('path').value='';"
                                                        class="form-control">
        <input type="submit" value="View File">
    </form>
</div>
<pre>
<code class="blueAndGrey">
<?php

    GLOBAL $text;
    print($text);
?>
</code>
</pre>
</body>
</html>