Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-07
5
Medium Priority
?
225 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:Simon336697
  • 3
  • 2
5 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22911230
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22911389
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
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 22911410
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
 
LVL 1

Author Comment

by:Simon336697
ID: 22911429
Hielo THAT WORKS GREAT MATE.
As usual.....you are just the best mate.
Thanks Hielo :>)
0
 
LVL 82

Expert Comment

by:hielo
ID: 22911437
you are welcome
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month20 days, 18 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question