pcs800 Posted November 14, 2007 Share Posted November 14, 2007 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? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 14, 2007 Share Posted November 14, 2007 use glob, I am not sure if it has flags on it for file types, but once you get the array fo files just test if it matches the extension desired. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 14, 2007 Share Posted November 14, 2007 use glob, I am not sure if it has flags on it for file types, but once you get the array fo files just test if it matches the extension desired. Edit: Sorry Double post, this site needs to get off mysql and go to oracle cause its just too full Quote Link to comment Share on other sites More sharing options...
pcs800 Posted November 15, 2007 Author Share Posted November 15, 2007 Thanks for the reply, I found glob but your reply seems to assume I would know how to use it for this function. I will read up on it, but any hand holding is appreciated. Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 15, 2007 Share Posted November 15, 2007 $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 Quote Link to comment Share on other sites More sharing options...
pcs800 Posted November 15, 2007 Author Share Posted November 15, 2007 cool, thanks! I will try it out now and let you know what happens. Quote Link to comment Share on other sites More sharing options...
pcs800 Posted November 15, 2007 Author Share Posted November 15, 2007 i created test.php and put in the code, I get this. $html_files = glob("*.htm*");//this will get all htm and html files $holder = "\n"; The folder I put it in has about 220 .htm files in it. Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 16, 2007 Share Posted November 16, 2007 Did you wrap <?php ?> tags around that code? o_o Quote Link to comment Share on other sites More sharing options...
pcs800 Posted November 16, 2007 Author Share Posted November 16, 2007 ahh yes, that certainly would help. Case in point (not a master coder) Quote Link to comment Share on other sites More sharing options...
pcs800 Posted November 16, 2007 Author Share Posted November 16, 2007 Ok, I set it up correctly now. All I get is a blank page now. I tried disabling a few lines but nothing happens. Here is the link to the page, there are html files in the folder with it. http://www.tuscolacounty.org/minutes/ag/test.php Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 16, 2007 Share Posted November 16, 2007 *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; ?> Quote Link to comment Share on other sites More sharing options...
pcs800 Posted November 16, 2007 Author Share Posted November 16, 2007 Sorry i am not up to your standars with php coding. Thanks very much for supplying the code, it is appreciated. When a user chooses a link from the generated drop down list, nothing happens. how can I have it open the link in a new window/tab? Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 16, 2007 Share Posted November 16, 2007 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; ?> Quote Link to comment Share on other sites More sharing options...
pcs800 Posted November 16, 2007 Author Share Posted November 16, 2007 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. Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 16, 2007 Share Posted November 16, 2007 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; ?> Quote Link to comment Share on other sites More sharing options...
pcs800 Posted November 16, 2007 Author Share Posted November 16, 2007 Yes I understand the tab thing. the open in new window code doesn't work, nothing happens at all. Quote Link to comment Share on other sites More sharing options...
kratsg Posted November 16, 2007 Share Posted November 16, 2007 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; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.