Jump to content

Recommended Posts

Hello all;

I have a script that lists the contents of a Directory.  Everything fine so far.  It works great, as you can see here:

http://www.testnest.com/upload/list.php

 

The script for that page is here:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
// open this directory 
$myDirectory = opendir(".");

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

// close directory
closedir($myDirectory);

//	count elements in array
$indexCount	= count($dirArray);
// Print ("$indexCount files<br>\n");

// sort 'em
sort($dirArray);

// print 'em
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print("<TR><TH>Filename</TH><th>Filetype</th><th>Filesize</th></TR>\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("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
	print("<td>");
	print(filetype($dirArray[$index]));
	print("</td>");
	print("<td>");
	print(filesize($dirArray[$index]));
	print("</td>");
	print("</TR>\n");
}
}
print("</TABLE>\n");
?>
</body>
</html>

 

Here's where it goes so horribly wrong.  I cannot have the file within the Upload directory.  So, I moved the script out, and changed this:

$myDirectory = opendir(".");

to this:

$myDirectory = opendir("upload");

The result can be seen here:

http://www.testnest.com/listOut.php

 

As you can see, it's throwing errors now.  BTW, here are the offending lines:

Line 36: print(filetype($dirArray[$index]));

Line 39: print(filesize($dirArray[$index]));

 

Obviously, those two lines aren't referencing the Directory correctly, but I cannot for the life of me figure out why.  Any help would be much appreciated.

Thanks!

Kyle

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
// open this directory 
$myDirectory = opendir("upload");

// get each entry
while($entryName = readdir($myDirectory)) {

$dirArray[] = $entryName;
}

// close directory
closedir($myDirectory);

//count elements in array
$indexCount = count($dirArray);
// Print ("$indexCount files<br>\n");

// sort 'em
sort($dirArray);

// print 'em
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print("<TR><TH>Filename</TH><th>Filetype</th><th>Filesize</th></TR>\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("<TR><TD><a href=\"./upload/$dirArray[$index]\">$dirArray[$index]</a></td>");

print("<td>");

print(filetype("./upload/$dirArray[$index]"));

print("</td>");

print("<td>");

print(filesize("./upload/$dirArray[$index]"));

print("</td>");

print("</TR>\n");

}
}
print("</TABLE>\n");
?>

</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.