Page 1 of 1

Random file

Posted: Tue Jul 08, 2008 8:42 pm
by grgo
Hy, I would need a script where I would specify numbers of files(and path to this folder) in folder and then it woul pick a random number - files in folder would have names in number like 1.txt, 2.txt,..etc - and then it would echo file with that number. Then I would include that file in my page to display random content. I am already having script where I dont have to specify number of files and files dont have to be in numbers, but it's eating too much resources, because I have few included in page and a lot of files to choose from.
I know its simple script, but I have no knowledge of php.

Re: Random file

Posted: Wed Jul 09, 2008 2:41 am
by jaoudestudios
It would be faster and more efficient to use a mysql database.

Re: Random file

Posted: Wed Jul 09, 2008 4:35 pm
by grgo
Yes, but I have this script to use for multi use, as well as displaying pictures, and I think for somebody who knows php would take few minutes.

Re: Random file

Posted: Wed Jul 09, 2008 5:24 pm
by Benjamin
Put them into an array and use array_rand();

http://us3.php.net/manual/en/function.array-rand.php