newbe101
asked on
php EASY? write html table from data in folder
Hi all,
this one should be pretty easy. I have a folder with changing files. What I need to do is have php look into a folder, get all the file names with a php extension, then write an html table with the values of the folder contents in the table.
ie.
/stuff/
contains a.php, b.php x.php and y.php
so, write contents.html with value
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>a.php</td>
<td>b.php</td>
<td>x.php</td>
<td>y.php</td>
</tr>
</table>
I would have a sample code, but I have no idea where to start... thanks in advance.
this one should be pretty easy. I have a folder with changing files. What I need to do is have php look into a folder, get all the file names with a php extension, then write an html table with the values of the folder contents in the table.
ie.
/stuff/
contains a.php, b.php x.php and y.php
so, write contents.html with value
<table width="300" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>a.php</td>
<td>b.php</td>
<td>x.php</td>
<td>y.php</td>
</tr>
</table>
I would have a sample code, but I have no idea where to start... thanks in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
this is on a unix box... so I can change the path to a relative path... correct?
ASKER
OK, I actually need to write the data to a file... here is what I have come up with, but it doesnt' seem to be working....
$directory = "../../build/";
$headerext = ".html";
$headerfile = "../../build/$make$headere xt";
$fh = fopen($headerfile, 'w') or die("can't open file");
if($dir_handle = opendir($directory)){
$header = . "<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
$header = . "<tr>";
while($file = readdir($dir_handle))
{
if(eregi(".php", $file) && is_file($file))
{
$header = . "<td>$file</td>";
}
}
$header = . "</tr>";
$header = . "</table>";
}
closedir($dir_handle);
$stringData = $header;
fwrite($fh, $stringData);
fclose($fh);
$directory = "../../build/";
$headerext = ".html";
$headerfile = "../../build/$make$headere
$fh = fopen($headerfile, 'w') or die("can't open file");
if($dir_handle = opendir($directory)){
$header = . "<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
$header = . "<tr>";
while($file = readdir($dir_handle))
{
if(eregi(".php", $file) && is_file($file))
{
$header = . "<td>$file</td>";
}
}
$header = . "</tr>";
$header = . "</table>";
}
closedir($dir_handle);
$stringData = $header;
fwrite($fh, $stringData);
fclose($fh);
ASKER
OK, I fixed it somewhat. It is now creating the file with the table structure, but it is not including the <td>$file</td> part... here is what I have:
$directory = "../../build/";
$directory2 = "../../build/$make1";
$headerext = ".html";
$headerfile = "../../build/$make1$header ext";
if($dir_handle = opendir($directory2)){
$header .="<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
$header .="<tr>";
while($file = readdir($dir_handle))
{
if(eregi(".php", $file) && is_file($file))
{
$header .="<td>$file</td>";
}
}
$header .="</tr>";
$header .="</table>";
}
closedir($dir_handle);
$fh = fopen($headerfile, 'w') or die("can't open file");
$stringData = $header;
fwrite($fh, $stringData);
fclose($fh);
$directory = "../../build/";
$directory2 = "../../build/$make1";
$headerext = ".html";
$headerfile = "../../build/$make1$header
if($dir_handle = opendir($directory2)){
$header .="<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
$header .="<tr>";
while($file = readdir($dir_handle))
{
if(eregi(".php", $file) && is_file($file))
{
$header .="<td>$file</td>";
}
}
$header .="</tr>";
$header .="</table>";
}
closedir($dir_handle);
$fh = fopen($headerfile, 'w') or die("can't open file");
$stringData = $header;
fwrite($fh, $stringData);
fclose($fh);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it's not looping. It's only getting 1 file.
ASKER
oops... nevermind... I had to refresh the page... thanks guys.
Glad you got things work out :)
hongjun
hongjun
I personally feel the layout is not really friendly.
hongjun