Hi,
Please bear with me, I have no real experience with PHP but am using it for the first time in a page for maintenance purposes.
One of the things I am trying to do is include a random page from within a certain folder (folder: 'modules/did-you-know'). Inside this folder there are currently three files named in this format 'did-you-know-###.php' - where ### is the page number.
I have no problems including the named page individually, but it is when randomising it where it causes errors.
The code I am using is the following:
<?php
$i=0;
$myDirectory = dir("modules/did-you-know");
while($file=$myDirectory->read())
{
$array[$i]=$file;
$i++;
}
$myDirectory->close();
$num = count($array);
$random = rand(0, $num);
include "$array[$random]"; ?>
When I load the page, I get numerous errors, as follows:
Warning: include(..) [function.include]: failed to open stream: Operation not permitted in /home/{USERNAME}/public_html/test2/index.php on line 103
Warning: include(..) [function.include]: failed to open stream: Operation not permitted in /home/{USERNAME}/public_html/test2/index.php on line 103
Warning: include() [function.include]: Failed opening '..' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/{USERNAME}/public_html/test2/index.php on line 103
Warning: include(did-you-know-002.php) [function.include]: failed to open stream: No such file or directory in /home/{USERNAME}/public_html/test2/index.php on line 103
Warning: include(did-you-know-002.php) [function.include]: failed to open stream: No such file or directory in /home/{USERNAME}/public_html/test2/index.php on line 103
Warning: include() [function.include]: Failed opening 'did-you-know-002.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/{USERNAME}/public_html/test2/index.php on line 103
Now, it's clear from the above that it is (at least sometimes) reading the files from within the 'did-you-know' directory, so not sure why I am getting these errors. (Especially the last one, as that would suggest an error to do with permissions, would it not?)
Line 103 is the "include" line.
Any help would be appreciated.
Thanks