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?
 
hieloConnect With a Mentor Commented:
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
 
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
 
Simon336697Author Commented:
Hielo THAT WORKS GREAT MATE.
As usual.....you are just the best mate.
Thanks Hielo :>)
0
 
hieloCommented:
you are welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.