Random file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grgo
Forum Newbie
Posts: 6
Joined: Fri Jun 06, 2008 3:49 pm

Random file

Post 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.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Random file

Post by jaoudestudios »

It would be faster and more efficient to use a mysql database.
grgo
Forum Newbie
Posts: 6
Joined: Fri Jun 06, 2008 3:49 pm

Re: Random file

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Random file

Post by Benjamin »

Put them into an array and use array_rand();

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