Jump to content

Show html files in a folder


pcs800

Recommended Posts

$html_files = glob("*.htm*");//this will get all htm and html files

$holder = "<select name='file'>\n";

foreach($html_files as $file){
$holder .= "\t<option value='$file'>$file</option>\n";
}

$holder .= "</select>\n";

 

Echo out the $holder variable where you want the dropdown list of html files to show on the page... You can include this in a form, submit it and do stuff with it :-o

*sighs* Copy the WHOLE CODE below straight into the php file, meaning that the only thing in the php file is the code below, no html, no anything.

 

 

<?php
$html_files = glob("*.htm*");//this will get all htm and html files

$holder = "<select name='file'>\n";

foreach($html_files as $file){
$holder .= "\t<option value='$file'>$file</option>\n";
}

$holder .= "</select>\n";

echo $holder;
?>

 

You would want it to re-direct as a new window? Or open in the current window? (Current window seems to be more applicable these days, so do this)

 

<?php
$html_files = glob("*.htm*");//this will get all htm and html files

$holder = "<select name='file' onchange='window.location = this.value;'>\n";

foreach($html_files as $file){
$holder .= "\t<option value='$file'>$file</option>\n";
}

$holder .= "</select>\n";

echo $holder;
?>

Here's the problem with new windows. Ever since the release of tabs in FireFox and IE, opening in a new window almost always opens up in a new tab, defeating the point... If you REALLY want it in a new window... try this (untested, but should work)

 

<?php
$html_files = glob("*.htm*");//this will get all htm and html files

$holder = "<select name='file' onchange=\"window.open(this.value,'mywindow','width=400,height=200,toolbar=yes,
location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,
resizable=yes')\">\n";

foreach($html_files as $file){
$holder .= "\t<option value='$file'>$file</option>\n";
}

$holder .= "</select>\n";

echo $holder;
?>

Let's try with regular links, hmmmm

 

<?php
$html_files = glob("*.htm*");//this will get all htm and html files

$holder = "Current HTML Files on our server:\n<br>";

foreach($html_files as $file){
$holder .= "<a href='$file' target='_blank'>$file</a><br>\n";
}

echo $holder;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.