Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

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.
Avatar of hielo
hielo
Flag of Wallis and Futuna image

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

Avatar of Simon336697

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hielo THAT WORKS GREAT MATE.
As usual.....you are just the best mate.
Thanks Hielo :>)
you are welcome