faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 15 people (33%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How can I read the filenames of files in a folder on a webserver and pass them to a Javascript Array

Apr 7th, 2008 22:35
ha mo, James Alexander, Nick Hearn,


Here's how I do it in my replay parser.
[/code]
<?php
$replays='';
$replays_dir = opendir('replays/');
while (false !== ($replay = readdir($replays_dir))) {
  if (substr($replay,-4)=='.w3g') {$replays.=','.$replay;}
}
$replays = str_replace('.w3g','',$replays);
echo('<script type="text/javascript">
var replays=\''.substr($replays,1).'\'.split(",");
</script>');
closedir($replays_dir);
?>
[/code]
Then the javascript.
[code]
var j = 0;
var t;
var rcount = 0;
var rint = 2500;
function doreplays1() {
unsure=confirm("Please wait until all your replays are listed below!");
if (unsure==true) {
j=0; rcount=replays.length;
document.getElementById('hideme').innerHTML='';
doreplays();
}
}
function doreplays() {
if (j<rcount) {
openpage('example.php?id='+replays[j]);
document.getElementById('answer').innerHTML+=replays[j]+'<br/ >';
j++;
t=setTimeout("doreplays()",rint);
} else {
  clearTimeout(t);
  document.getElementById('answer').innerHTML+='<br/ >Thats all of 
them.<br/ >';
}
}
/// winopt along with other variables here is adjustable.
function openpage(ulink) {
switch(winopt) {
case 0: document.getElementById('1').src=ulink; break;
case 1: window.open(ulink); break;
case 2: popupwin=window.open
(ulink,'info','width=800,height=300,scrollbars=yes,menubar=yes,resizable
=yes'); break;
} 
}
[/code]
Not sure if this will help or now
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com