包含文件信息的目录列表
我想制作一个目录列表,而不是整个
文件名,我需要它来显示文件名减去扩展名并得到
的值charname =在文件本身。
我被告知我必须将目录列表转换为数组
然后使用foreach (数组作为项目)"通过并打开每个文件
但是我尝试了几种不同的方法而且我无法让它工作。
我'已经能够使用这个脚本按顺序列出目录
但是之后我就输了。
<?
$ list = Array();
$ handle = opendir(''testdir /。'');
while(false!==($ file = readdir($ handle))){
if($ file!="。"&& $ file!=" .."){
$ list [] =($ file);
}
}
closedir($ handle);
sort($ list);
reset($ list);
while(list($ key,$ val)= each($ list) )){
echo"< a href = test.php?name = $ val> $ val< / a>< br>";
}
?>
这里我希望名字后面的$ val只是没有
的文件名
扩展(目录中的所有文件都是txt文件)然后是t他将
秒$ val显示在列表中,作为行的值
charname =在txt文件中。
任何人都知道我该怎么办?
Kim Jensen
I''d like to make a directory listing where instead of the entire
filename I need it to show the filename minus the extention and get the
value of charname= in the file itself.
I''ve been told that I had to turn the directory listing into an array
and then use "foreach (array as item)" to go through and open each file
but I''ve tried several different approaches and I just can''t get it to work.
I''ve been able to make it list the directory in order using this script
but after that I''m lost.
<?
$list = Array();
$handle = opendir(''testdir/.'');
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$list[] = ($file);
}
}
closedir($handle);
sort ($list);
reset ($list);
while (list ($key, $val) = each ($list)) {
echo "<a href=test.php?name=$val>$val</a><br>";
}
?>
Here I''d like the $val after the name= to be just the filename without
the extention (all files in the directory are txt files) and then the
second $val which it shows in the list to be the value of the line
charname= in the txt files themselves.
Anybody have an idea what I should do?
Kim Jensen
list = Array();
list = Array();
handle = opendir(''testdir /。'');
while(false!==(
handle = opendir(''testdir/.'');
while (false !== (
file = readdir(
file = readdir(