Forum Moderators: coopster

Message Too Old, No Replies

automate checking file verification

         

cporto

8:08 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



I'm trying to simplify my life. Right now I have and index page. In the index page I have $pass variable.
In that variable is an array of names.
Thanks to Kami in a previous post, the method below checks to see if a the url variable id is equal to one of the $pass names if so its loads its value to $page

What I would like to do is automate the $pass array. that list is actually a list of file names in a directory but with the file ext removed.
So far I can't find any information on what I would like to achieve on the board.


$pass = array('home','contact','error','etc');
$page="";
if (in_array($_GET['id'], $pass))
{
$page=$_GET['id'].".php";
}
elseif (!isset($_GET['id']))
{
$page="home.php";
}
else
{
$page="error.php";
}

Thanks ahead of time for any help!

lobo235

6:25 am on Nov 19, 2005 (gmt 0)

10+ Year Member



So you want it to automatically create the $pass variable using the files in a folder?

Use the dir class [php.net] that is built into PHP. There is a good example on the page that shows how to do it.

If you need additional help, just reply and I can help you with the details.

Netizen

1:08 pm on Nov 19, 2005 (gmt 0)

10+ Year Member



Alternatively you could use the glob [php.net] function.

Example:

If you want to list all the .txt files you could do something like

foreach (glob('*.txt') as $filename) {
$pass[]=str_replace('.txt','',$filename);
}

cporto

4:38 pm on Nov 22, 2005 (gmt 0)

10+ Year Member



Thanks! I eventually figured it out on my own. But the solution was similar to Netizen.

Thanks Again!