Link to home
Start Free TrialLog in
Avatar of newbe101
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.
ASKER CERTIFIED SOLUTION
Avatar of hongjun
hongjun
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
However, you may wish to rearrange the layout.
I personally feel the layout is not really friendly.

hongjun
Avatar of newbe101
newbe101

ASKER

this is on a unix box... so I can change the path to a relative path... correct?
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$headerext";
$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);
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$headerext";

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
it's not looping.  It's only getting 1 file.
oops... nevermind... I had to refresh the page... thanks guys.
Glad you got things work out :)


hongjun