I'm pretty new to PHP and wanted to do some neat things with it, so I set up a home web server where I can practice!
Well this is what I want to do:
I want to get a list of files in a directory:
CODE
if ($handle = opendir("files/download")) {
/* Loop De Loop */
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") { //TY php.net :)
echo "$file(HTML ~ To setup a table(like Image Below))";
}
}
closedir($handle);
}
/* Loop De Loop */
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") { //TY php.net :)
echo "$file(HTML ~ To setup a table(like Image Below))";
}
}
closedir($handle);
}
I used to know some Java, and this is kinda how I read data from a file (looks similar). So I hope that is correct? :S
I want to get each file that it reads from the directory and set up a table in HTML for it (A table that has links to downloads which are the files in the directory).

The reason it's complicated is because I want the script to get the file name, filesize, and output them both into the next corresponding row and under each correct column. The file size I already know how to do.
CODE
$fileName = round(filesize("pathtothefile") / 1048576, 2);
I just don't know how to get them into the right column.
The other way I was thinking is making a function:
CODE
function listNames() {
if ($handle = opendir("files/download")) {
/* Loop De Loop */
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
}
}
if ($handle = opendir("files/download")) {
/* Loop De Loop */
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
}
}
Then a function to get the fileSize, and just call them in each row that I need them. But I know there's got to be a more efficient way of doing this? Pretty much its for when I decide to add a new file to the folder, it will already have done everything on the HTML page, without much interaction with the page itself(coding, etc), because the script reads the folder, and that's that.
Any thoughts on how I can achieve this?
