Results 1 to 7 of 7

Thread: PHP Include (Most Recent HTML File)?

  1. #1
    Wannabe Geek ButtermilkJack's Avatar
    Join Date
    Feb 2006
    Location
    Dublin, Ireland
    Posts
    270
    Post Thanks / Like

    Default PHP Include (Most Recent HTML File)?

    I'm trying to use the php include function to call a html file into a php page. The html files are just residing in my root folder as there's no need to keep them in a database just yet. However, I want to be able to call the most recent html file each time. Do I need to use a database for this? Is there any other way to date-stamp the html files?

  2. #2
    Wannabe Geek
    Join Date
    Sep 2006
    Posts
    195
    Post Thanks / Like

    Default

    Use the 'system' command with 'stat filename' and then rip out the bit you're interested in?

    Why do you want to put your html files in a database? Seems a bit overly complex...

  3. #3
    Senior Member louie's Avatar
    Join Date
    Jan 2006
    Location
    Dublin, Ireland
    Posts
    2,423
    Post Thanks / Like

    Default

    yes use a database and just store the path to the file including the date last modified, so you can access the last one all the time.
    :. Web Design & Development Web Design Ireland
    :. Search Engines Optimization Search Engines Optimization
    :. Car Parts & Accessories Car Parts
    :. Cars Ireland Cars Ireland
    :. I Have 2 Find It Directory SEF Directory

  4. #4
    Wannabe Geek ButtermilkJack's Avatar
    Join Date
    Feb 2006
    Location
    Dublin, Ireland
    Posts
    270
    Post Thanks / Like

    Default

    Quote Originally Posted by dude View Post
    Use the 'system' command with 'stat filename' and then rip out the bit you're interested in?

    Why do you want to put your html files in a database? Seems a bit overly complex...
    Hi, thanks for the reply. I don't want to put my html files in a database. That's the thing. I'm trying to find a way of doing it so that I can just keep them in the root folder.

    I'm just beginning with PHP so am not to up on system and stat filename but I'll look into it. Cheers!

  5. #5
    Hosting Caretaker niall's Avatar
    Join Date
    Jan 2007
    Location
    Carlow
    Posts
    87
    Post Thanks / Like

    Default

    Quote Originally Posted by ButtermilkJack View Post
    Hi, thanks for the reply. I don't want to put my html files in a database. That's the thing. I'm trying to find a way of doing it so that I can just keep them in the root folder.
    A database would be total over kill for this. Use opendir to open the directory containing the html files and readdir to loop through the files in the directory. For each html file, use filectime to see when the file was last changed.

    The basic code to get the file you want is:
    PHP Code:
    $dirname="/path/to/html/";
    $filename="";
    $filetime=0;

    $dir=opendir($dirname);
    while(
    $file=readdir($dir))
    {
        if(
    $file != '.' && $file != '..')
      {
        if(
    filectime($file) > $filetime)
        {
          
    $filename=$file;
          
    $filetime=filectime($file);
        }
      }
    }
    print 
    "$dirname$file\n"
    This is a totally untested quick and dirty example There is plenty of error checking that can be added (did the directory open, is the file html etc.) but it should get you pointed in the right direction without the pain of adding a database to the mix.

  6. #6
    Hosting Caretaker niall's Avatar
    Join Date
    Jan 2007
    Location
    Carlow
    Posts
    87
    Post Thanks / Like

    Default

    Actually, replace all instances of filectime with filemtime, that will give you the last modified time which is what you need.

    Niall

  7. #7
    Wannabe Geek ButtermilkJack's Avatar
    Join Date
    Feb 2006
    Location
    Dublin, Ireland
    Posts
    270
    Post Thanks / Like

    Default

    Excellent niall, that sounds perfect. Thanks a million. I'll try it out now!

    Just to fill you in, I run a local football club website and have to update the fixtures/results page each week. It's not archived at the moment so all I want to do is create the html file, dump it into a folder in the root and let the webpage call it up.

    This script should do the job nicely

Visitors found this page by searching for:

php most recent file

most recent file in php

php include html file

php get newest filephp find most recent filephp get most recent filephp include latestphp include newest filefile most recent phpphp find newest filephp include most recent filephp include latest files in directoryphp open newest filephp include most recentselect most recent file phpmost recent file phpphp include latest filemost current file phpphp get latest fileDisplay most recent file with phpphp open recent filesfind most recent file phpphp return newest filephp readdir display Most recent latest newest file in a directory by datephp read most recent files in directory

Tags for this Thread

Posting Permissions

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