Results 1 to 8 of 8

Thread: Use Java to list files in a directory and then pull into an iframe

  1. #1
    Join Date
    Feb 2012

    Use Java to list files in a directory and then pull into an iframe

    Hello and thank you in advance for your time!
    I am building a page that will display a file in an iframe.
    The problem is that the files won't necessarily be static.
    We are collecting weather data at 1 min. intervals which is saved into a flat file. I will be uploading these files (and re-uploading at set intervals) into a set directory with a naming scheme of Feb12log.* (type of file doesn't really matter. could be .txt, .csv, .xls) but the name will change corresponding with the month & year: {MMM}{DD}log.{ext}. Each month, a new file is created
    I can successfully pull a file into an iframe. I can build a drop box and a static list of files (File1, File2, File3 etc). I am pretty sure that I can build a search box in the page that will parse the information in the iframe (Ctrl+F would work as well I guess). Hopefully this is enough background info.
    Instead of building a page for each new month ad nauseam, I would love to be able to pull a list of files currently in the upload directory into a dropdown box and when a file is selected, have it display in an iframe on the same page. The ability to be able to search the page would be awesome.
    So I can pull a drop down from an array:

    <script language="javascript">
    function optionSel(selectbox,text,value )
    	var optn = document.createElement("OPTION");
    	optn.text = text;
    	optn.value = value;
    function Option_list(selectbox){
    var month = new Array("Jan12","Feb12","Mar12","Apr12","May12","Jun12","Jul12","Aug12","Sep12","Oct12","Nov12","Dec12");
    for (var i=0; i < month.length;++i){
    optionSel(document.drop_list.Month_list, month[i], month[i]);
    <body onLoad="Option_list()";>
    	<FORM name="drop_list" action="yourpage.php" method="POST" >
    		<SELECT  NAME="Month_list">
    			<Option value="" >Month list</option>
    And I have figured out how to pull multiple links into a target iFrame:

    <TITLE>Site Current Month Totals</TITLE>
    	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <TD><H4>Monthly Totals</H4>
    <LI><A HREF="Jan12log.txt" TARGET="DisplayWindow">Document 1</A>
    <LI><A HREF="Feb12log.txt" TARGET="DisplayWindow">Document 2</A>
    <LI><A HREF="Mar12log.txt" TARGET="DisplayWindow">Document 3</A>
        WIDTH=1024 HEIGHT=480>
    Does anyone have an idea for code for a recursive search that can read a directory into an array? It could be a server side script.
    If I can figure that out, and figure how to tie it all together, the only thing left is to format the directory list as links and it should be good.

    I am not looking for a handout, and I appreciate any input at all. My questions are: 1. Is this possible? Or should I resign myself to manually creating new pages every month? 2. Would anyone be able give me a nudge in the correct direction?
    Thanks again!

  2. #2
    Join Date
    Mar 2007
    JS can't read the content of a folder unless a server-side script makes the data available, and if you can do that then why not just use server-side code to generate the list of options?

    Alternatively if you're using a consistent naming scheme, a script could use the date to predict the contents of the folder.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  3. #3
    Join Date
    Feb 2012

    Thanks for the response!

    Quote Originally Posted by Logic Ali View Post
    JS can't read the content of a folder unless a server-side script makes the data available, and if you can do that then why not just use server-side code to generate the list of options?
    Alternatively if you're using a consistent naming scheme, a script could use the date to predict the contents of the folder.
    @Logic, Thank you for the response. The directory portion would be server-side, but I do not know where to start on that (I Perhaps posted in the wrong forum). I suppose reading the contents into an array might not be too difficult (although I can't seem to wrap my mind around it)..but then how to pass that array to the client in order to populate the the drop down????

  4. #4
    Join Date
    Oct 2010
    Versailles, France
    You can always build javascript files with php for the preceding months (or days for the current month) to load this scripts dynamically. Then you have only to read with PHP the files of the day.

  5. #5
    Join Date
    Feb 2012

    To Clarify

    Again, thanks for the replies.
    To clarify a bit: I will have a directory on a web server "WeatherFiles". I am looking to build a script that will read a list of files in that directory into an array (or something else, if better suited).
    From that array, I plan to populate a drop down box (Or even just a list) with the list of those files (which I hope to make links) that will then, when clicked populate an iFrame on the same page.
    Through all of my searches, I cannot seem to find something that will fit the bill. I now understand that the script or piece of programming that polls the directory needs to be server side, I just have no idea where to start in order to build it....

  6. #6
    Join Date
    Oct 2010
    Versailles, France
    You have to work on the server with PHP and with readdir.
    There is not very difficult to build a list of files with this kind of script (index.php) to run on a server (like to test EasyPHP, WAMP or an other local server)

      	$dir = opendir("WeatherFiles");
    	//List files in WeatherFiles directory
    	while (($file = readdir($dir)) !== false){
    		// conditions on filenames
      		if ($file!='.' && $file!='..') $lst.=",".$file;
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="fr">
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="generator" content="PSPad editor, www.pspad.com">
    <style type="text/css">
    <script type="text/javascript">
    // we display our string (without the first comma) in a javascript var
    var lst="<?php echo substr($lst,1); ?>".split(','); //to build an array
    Good luck !
    The you will be able to build different arrays, to sort them and so on... (See array, array functions, sort, explode, implode...)
    Last edited by 007Julien; 02-07-2012 at 08:42 AM. Reason: complements

  7. #7
    Join Date
    Feb 2012

    I will give it a go

    Thank you for the reply!
    I will install php on the server and give it a whirl!
    I will post back when I have a result.

  8. #8
    Join Date
    Nov 2002
    Flint, Michigan, USA
    You could use AJAX to first pull the list and again later to pull the selected file. That way you don't need to make any changes to the server.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10194 seconds
  • Memory Usage 2,934KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (8)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates