Thanks to the suggestion of using the glob() function, I am now able the find all of the directories and display them for the user. When the user selects a directory, I need to display the html page within the directory. Not sure if this test code is the most efficient way to get the file name:

<?php
//$rvars = $_REQUEST;
//$dir = $rvars["dir"];
$dir = "20090211";
if ($dir) {
$fullfilename = glob("./" . $dir . "/*.html");
$filename = basename($fullfilename[0]);
echo $filename . "<br>"; // Testing
}
?>

Now that I have the file name for the html file, how do I display the html page?

Probably something super simple....

Todd

    According to the manual, PHP has a function called [man]readfile[/man].

      maybe you can replace:
      echo $filename . "<br>"; // Testing
      with
      if ( is_file( $filename . '/index.html' ) )
      {
      require ( $filename . '/index.html' );
      }

        This is the code I use to display the edition of the Rotary newsletter, Viewpoint, however, I am not a "clever" user of PHP. So, suggestions on improving the script is always welcomed.

        Todd

        <?php
        // The name of the directory containing the selected Viewpoint is
        // passed in the URL
        $rvars = $REQUEST;
        $vp_dir = $rvars["dir"];
        $path_parts = pathinfo($
        SERVER["SCRIPT_NAME"]);
        $server = $_SERVER["HTTP_HOST"];

        // Create the URL to the Viewpoint HTML file
        $http_path = "http://" . $server . $path_parts["dirname"] . "/" . $vp_dir . "/";

        if ($vp_dir) {
        // Get the first HTML file in the directory (there should only be one)
        $fullfilename = glob("./" . $vp_dir . "/*.html");
        $filename = basename($fullfilename[0]);

        // Create the target URL
        $target = $http_path . $filename;
        header("location: " . $http_path . $filename);

        }
        ?>

          echo file_get_contents("index.html");

          will display the file contents.

            As I recall, the images on the page did not display. They are referenced as

            src="images/PVRC_Header.gif"

            Maybe I made an error in the code....I'll try it again.

            Todd

              rtcary;10924492 wrote:

              As I recall, the images on the page did not display. They are referenced as

              src="images/PVRC_Header.gif"

              Maybe I made an error in the code....I'll try it again.

              Todd

              are they on the same server?

                The images are in an images directory in the same directory as the HTML file.

                Todd

                  I retried readfile($filename) and echo file_get_contents($filename), and both do not display the images (I assume since they are relative).

                    rtcary;10924503 wrote:

                    I retried readfile($filename) and echo file_get_contents($filename), and both do not display the images (I assume since they are relative).

                    yeah the problem is, your basically printing the html from the file into the page your viewing, which is not in the same directory where the images are. maybe someone else has a quick solution.

                      ok so i tried this and it worked, just change your variables

                      dir is the directory name

                      $get_file =  file_get_contents("dir/index.html");
                      
                      echo str_replace('src="images/', 'src="dir/images/', $get_file);
                      

                      let me know if that worked for ya

                        If you have any suggestions on tightening up my working code, I am open to suggestions. Is there a better way to get the data for building the URL e.g. server, current directory, file name.

                        Works, yes...tight, ??? :-)

                        Todd

                          When I get back from my client I'll try the replace...

                          Thanks...

                          Todd

                            Write a Reply...