listing files - some won't show

Hi. I’m very noob.

The page flamencopeko.net/lyrics.php will only show some filetypes like .jpg and .ico, but not .txt for instance.

This is the code:

[php]

<?php // open directory $myDirectory = opendir("lyrics"); // get entries while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } // close directory closedir($myDirectory); // count elements in array $indexCount = count($dirArray); // show number of songs print("
\n"); Print ("$indexCount songs in table
\n"); print("

\n"); // sort files sort($dirArray); // print files print("\n"); // cellpadding=5 class=whitelinks print("\n"); // loop through the array of files and print them all for($index=0; $index < $indexCount; $index++) { if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files print(""); print(""); print(""); print("\n"); } } print("
title type size
$dirArray[$index]"); print(filetype($dirArray[$index])); print(""); print(filesize($dirArray[$index])); print("
\n"); ?>

[/php]

MC Peko

This is the error:

Warning: filetype() [function.filetype]: Lstat failed for New Text 2.txt in /usr/home/sys/www/cccp/flamencopeko/lyrics.php on line 52

MC Peko

Strangely renaming a .txt file to .jpg gives the same error.

I see now that problem is that filename is read from lyrics folder as it should, but type and size from home folder.

So problem is not solved. Also why does it list two extra files, and where do I put ‘-2’?

Another solution I tried now, that works, is to put the lyrics.php file (and rename it to index.php) in the lyrics folder. But then I need to know how to exclude the index.php file itself from the table listing.

Fixed the counting thing with this:

[php]$indexReal = $indexCount-2;[/php]

Then just printing that.

I’ve expanded the table a bit. Still need to show only .txt files. And the number index starts at 2, not 1.

http://flamencopeko.net/lyrics/

This is the new code. The file is named index.php, and resides in a folder named lyrics along with the .txt files.

[php]

// open directory
$myDirectory = opendir(".");

// get entries
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}

// close directory
closedir($myDirectory);

// count elements in array
$indexCount = count($dirArray);
$indexReal = $indexCount-2;

// show number of songs
print("

\n");
Print (“Songs in table: $indexReal.
\n”);
print("

\n");

// sort files
sort($dirArray);

// print table
print("

\n");
print("\n");

// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != “.”){ // don’t list hidden files
print("

");
print("");
print("");
print("");
print("\n");
}
}
print("
# title type size
$index");
$content = file($dirArray[$index]);
echo ("<a href="$dirArray[$index]">$content[0]");
print("
");
print(filetype($dirArray[$index]));
print("
");
print(filesize($dirArray[$index]));
print("
\n");

[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service