Populating a select box with files from a folder with certain criteria

Hi guys hope u are well.

Guys id like to create a select box that is populated by:

1) Polling a folder for files that have:
2) backup*.php as the criteria
3) On selection of the file in the select box, to go to that page

Any help greatly appreciated.
LVL 1
Simon336697Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
try:
<?php
//assuming the files are at http://www.yoursite.com/somefolder/*
$folderPath ="/somefolder";
$files = glob( "$_SERVER['DOCUMENT_ROOT']/$folderPath/backup*.txt" );
if( count($files) )
{
  echo "<select onchange='location.href=this.value;'>";
  foreach ($files as $filename) {
    echo "<option value='$folderPath/$filename'>$filename</option>";
  }
  echo "</select>";
}
?>

Open in new window

0
Simon336697Author Commented:
Hi Hielo, mate thank you.
I tried this with the following code in the code snippet, but getting an error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\dropdowndbpilot\pagination\lab\scripts\backup\backup_main_page.php on line 156

The lines 155 and lines 156 in my code are:

$files = glob( "$_SERVER['DOCUMENT_ROOT']/$folderPath/backup*.php" );
if( count($files) ){


<?php
//assuming the files are at http://www.yoursite.com/somefolder/*
$folderPath ="/dropdowndbpilot/pagination/lab/scripts/backup";
$files = glob( "$_SERVER['DOCUMENT_ROOT']/$folderPath/backup*.php" );
if( count($files) ){
  echo "<select onchange='location.href=this.value;'>";
  foreach ($files as $filename) {
    echo "<option value='$folderPath/$filename'>$filename</option>";
  }
  echo "</select>";
}
?>

Open in new window

0
hieloCommented:
try:
<?php
//assuming the files are at http://www.yoursite.com/somefolder/*
$folderPath ="/dropdowndbpilot/pagination/lab/scripts/backup";
 
$files = glob( "{$_SERVER['DOCUMENT_ROOT']}{$folderPath}/*.xml" );
if( count($files) ){
  echo "<select onchange='if(this.value){location.href=this.value;}'><option value=''>Make a selection</option>";
  foreach ($files as $filename) {
  $filename=basename($filename);
    echo "<option value='$folderPath/$filename'>$filename</option>";
  }
  echo "</select>";
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author Commented:
Hielo THAT WORKS GREAT MATE.
As usual.....you are just the best mate.
Thanks Hielo :>)
0
hieloCommented:
you are welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.