如何动态读取本地文件?

how to dynamically read in local files?

我为网站制作了各种图片幻灯片。现在每个幻灯片图像都是一个存储在无序列表中的列表项,我使用 java 脚本和命名约定来写出每个列表项。示例:

for (j = 0; j<imageFileLength; j++){
    $('ul#Slider').append('<li><img src="'+fileName+'/0'+j+'.png" /></li>');} //write list items for each image
 });

这工作了一段时间,但现在我不能再像这样硬编码了。任何人都需要能够将文件放入我的文件夹中,最好使用任何名称,并且它们将作为列表项自动添加到无序列表中。

我需要使用 IE 8,这有点问题。它不支持 HTML 文件 API,也不支持使用 PHP,但我也许可以打开它。

有什么想法吗?或者,如果 PHP 是解决问题的好方法,那么该怎么做?也许 java 通过 netbeans?

谢谢

看看http://php.net/manual/en/function.dir.php

文档中有以下示例,它应该会让您找到您正在寻找的路径:

<?php
$d = dir("/etc/php5");
echo "Handle: " . $d->handle . "\n";
echo "Path: " . $d->path . "\n";
while (false !== ($entry = $d->read())) {
   echo $entry."\n";
}
$d->close();
?>

上面的例子会输出类似于:

句柄:资源 ID #2 路径:/etc/php5 . .. 阿帕奇 计算机生成 cli

这是正在使用的代码,没有任何问题。

$folder = 'images/';
$filetype = '*.jpg'; /* use the file extension you would read; here its jpg file */
$files = glob($folder.$filetype);
$count = count($files);
echo '<ul id="slider">';
for ($i = 0; $i < $count; $i++) {
    echo '<li>';
    echo '<img src="'.$files[$i].'" />';
    echo substr($files[$i],strlen($folder),strpos($files[$i], '.')-strlen($folder)); /* display name of the file */
    echo '</li>';
}
echo '</ul>';