Hello mistygirl-ga
Thank-you for your question.
I have written a small script for you that should do as you require.
It was not clear how the script should take the html page from the
list so I have taken my best guess which was to pick a random file
from the directory. If this is not how you wish to achieve this
please ask for clarification and state how you would like it to be
done.
The following script should be saved in a directory or folder
containing the html files and be called "random.php". A cron job
should then be set up to run the script every day. The script will
randomly select a file from the directory and save it as index.html in
the directory above it.
You may need to tweak the file and file permissions on your server in
order for it to work precisely as you require but should you need any
further assistance please do not hesitate to ask for clarification.
<?php
// read all the files in the directory into an array
$handle=opendir(".");
$dirarray = array();
while ($file = readdir($handle))
{
// make sure the file is not this one!
if ($file > ".." && $file != "test.php" ) {array_push($dirarray,$file);}
}
closedir($handle);
// pick a random file and save it as index.html
// in the directory above this one
srand ((double) microtime() * 10000000);
if (!copy($dirarray[array_rand($dirarray)], "../index.html")) {
echo "failed to copy...\n";
}
?> |
Request for Answer Clarification by
mistygirl-ga
on
26 Nov 2005 17:18 PST
wonderful!
Only problem is I don't want it to be random..... how do I tweak it to
take the html files in order? (take day1.html, first day, day2.html
second.... etc.)
|
Clarification of Answer by
palitoy-ga
on
27 Nov 2005 01:33 PST
Can you tell me a little bit more about the list of files? Do you
have a certain page on a certain day of the month? How many files are
there? Does the list change?
|
Clarification of Answer by
palitoy-ga
on
27 Nov 2005 02:02 PST
I was thinking of implementing this like this:
<?php
// create an array with the files you wish to use in
$dirarray[1] = "day1.html";
$dirarray[2] = "firstday.html";
$dirarray[3] = "day2.html";
..etc..
$dirarray[31] = "day31.html";
// copy the element in the array corresponding to today's date
if (!copy($dirarray[date("j")], "../index.html")) {
echo "failed to copy...\n";
}
?>
To use this you would need to set up the array to have 31 elements
(one for each day of the month. The script would then take the date
and copy the page you wished depending on the day of the month.
Let me know if this is of use or how you would like it to be
implemented in more detail (as per my previous clarification).
|
Request for Answer Clarification by
mistygirl-ga
on
28 Nov 2005 20:16 PST
31 days will be fine.... :-)
Just to be clear here:
So the final script is called test.php, and it's placed in a folder
called random.php with 31 html pages named day1.html day2.html etc.
Then I have to get my system admin to set up cron to run test.php once
a day, and walk away.
Is that right?
One more quick question... if it fails to copy.... what happens?
|
Clarification of Answer by
palitoy-ga
on
29 Nov 2005 02:17 PST
That is nearly correct! Simply save the script as random.php into a
folder containing all the HTML files. (You will need to add the
additional names of the files to the beginning of the script.) Then
simply instruct your system admin to have the random.php script run by
cron as you suggested.
If the script fails to copy a message will be printed saying "failed
to copy...", your system admin should be able to set it up so that you
receive an email each time the script is executed. Obviously if the
script fails to copy the index.html page will not be changed.
Let me know if you need anything else.
|