Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Location
    Park City, Utah
    Posts
    189
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Script to diplay included HTML pages

    I am looking for a script that works like 'include' only instead of just including 1 HTML file, it will include all the HTML files in a designated directory. If I can do this, it avoids updating 3 different HTML pages with the 'include' coding and I can just have the user upload the html file to the 'include' directory instead of editing the HTML page.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Script to diplay included HTML pages

    When you say script, do you mean a server-side script like ASP? ASP pages use VBScript, so you can pretty easily write code to retrieve all the files in a folder. On the other hand, if you mean a client-side script, then it's quite unlikely that you could retrieve all the file names in a folder on the server... there's no readily accessible public interface for that (and certainly you wouldn't include any privileged passwords in a client-side script).

  3. #3
    Star Lounger
    Join Date
    Sep 2004
    Location
    Wolverhampton, Staffordshire, England
    Posts
    86
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Script to diplay included HTML pages

    You could always have a single file with all the include files in, then include that file in the pages. e.g.

    include/include_root.php :
    <code>
    <?php
    include('include/page1.php');
    include('include/page2.php');
    include('include/page3.php');
    ?>
    ----------
    </code>
    index.php:
    <code>
    <html>
    ...
    <?php
    include('include/include_root.php');
    ?>
    ...
    </html>
    ---------
    </code>
    This may save some time in the long run, as per a script for directory inclusion... Perhaps you can create a php script that uses a method that scans the dir, and includes each file,

    include/include_root.php:
    <code>
    <?php
    /*****************************************
    * Code by Noirenex, www.noirenex.com *
    * includes all files found in a direcory *
    *****************************************/
    $count = 0;
    if ($dir = opendir('include/')) { //Directory of your includes
    while (false !== ($file = readdir($dir))) {
    if ($count>1){ //Removes the . and .. that is returned from readdir
    $file_array[$count - 2] = $file; //Appends the files found to an array
    }
    $count++;
    }
    closedir($dir);
    foreach($file_array as $inc_file){ //Cycle through the file array, include each file
    include ("include/".$inc_file); //Ensure root dir is same as your opendir()
    }
    }else{
    echo "Error.";
    }
    ?>
    </code>
    index.php remains the same

    Feel free to use without my header, i attached a fully functional example, with all neccessary items. Be careful what you put in your include directory.

    This also assume you have php support.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •