Right i'm in the process of designing a web page for a property company and the owner has requested a random property be displayed each day.
I have modified a quote of the day script to work with a filemtime method but its not working and im stumped, fairly sure i'm being an idiot though!
All php & txt files are located in the root directory.
I have 10 quotes(for now) in a file called Quotedata.txt All these quote occupy one line.
I then have a file called TodaysQuote.txt which at the moment contains the following on ONE line.
<img src="images/house_1.jpg" width="85" height="64" alt="house 1" class="left" /><p>This is a demo text. It will be replaced by the original. This is a demo text. It will be replaced by the original. This is a demo text.</p><p class="readmore"><a href="">Read More</a></p>
I then have this file called quoteGenerate.php which i suspect is where the problem lies.
<?php
if (time() - filemtime('todaysQuote.txt') > 86400)
{
$file = "todaysQuote.txt";
// read the file into an array
$quoteArray = file("quoteData.txt");
//get the random number
$qrnd = rand(0,sizeof($quoteArray)-1);
// pick quote name from random numbers
$quote = "$quoteArray[$qrnd]";
//write the string to the file
// Note: mode 'w' opens for writing only; place the file pointer at
// the beginning of the file and truncate the file to zero length.
// If the file does not exist, attempt to create it.
$fh = fopen($file, "w");
fputs($fh, $quote);
fclose($fh);
}
}
?>
I am then calling the quote on the webpage
by using the following script.
<?php
// display quote of the day
$file = "todaysQuote.txt";
$fh = fopen($file, "r");
$string = fread($fh, filesize($file));
fclose($fh);
echo "$string";
?>
what have i done wrong? any help very very appreciated.