automaticly displaying the most recent file in a blog style page
Posted 12 July 2006 - 01:05 AM
building a site which will be seeing many additions, blog style, which will be added inside a pre-determined folder. the file names contain all the info i need (date, name). what i'd like to do is have the home page open that folder, find the most recent file (by looking at their names, which as i've mentioned earlier will contain the date) and display that file by default, in the home page. possibly using the include() command. if one wishes to go backwards, a "back" button would be available, then the code would look for the 2nd most recent file. pressing the "back" button again would take the user to the 3rd most recent file, etc. on top of that, i'd like the <title> of my page to reflect the name of the currently displayed file, omiting the date.
ex: 2006.07.11.this is the title.txt
the code would see this as being the most recent file and include that by default in the home page. if tomorow i were to upload 2006.07.12.this is a new file.txt, then the home page would display that file by default, and to view the 11th of june file you'd simply have to press the "back" button.
basicly, making constant updates without ever having to touch the code.
possible? or pipe dreams?
Posted 12 July 2006 - 12:29 PM
<?php $k = (isset($_GET['k'])) ? $_GET['k'] : 0; //Get they array key from the URL $files = glob("path/to/your/files/*.txt"); //Get the list of files from your directory, they should be auto-sorted by default. $content = file_get_contents($files[$k]); //Get the content of the correct file in the $files array echo $content; ?>If you want to go back a file, increment $k - myscript.php?k=1 - Would go back a file.
Posted 12 July 2006 - 04:44 PM
Posted 12 July 2006 - 04:50 PM
Info: PHP Manual
Posted 12 July 2006 - 05:01 PM
Posted 12 July 2006 - 05:05 PM
Posted 12 July 2006 - 09:28 PM
but barring that i'm ready to look into using sql as it sounds perfect for what i'm trying to do
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users