Jump to content

Show html files in a folder


pcs800

Recommended Posts

I am not a great php programmer, but I eventually get things done :-)

I am trying to create a script that will parse the folder it's containing php page is in for html files. Create a drop down list of links to the html files.

Anyone know how I might do this?

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

*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;
?>

 

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

yes I agree, the current window is more the norm these days, but currently, all our document in this section open in a new window and that is how it needs to be.

 

this does work, so openning in a new window is the only part left.

I appreciate it.

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

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;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.