Topic: CSS for PHP display of a directory Pages that link to <a href="https://ozoneasylum.com/backlink?for=29556" title="Pages that link to Topic: CSS for PHP display of a directory" rel="nofollow" >Topic: CSS for PHP display of a directory\

 
Author Thread
K_C_
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Sep 2007

IP logged posted posted 09-23-2007 22:04 Edit Quote

OK, bear with me here, new to all of this.

I have a PHP file that reads the contents of a directory. I'd like to apply formating, at least specify a font, by CSS. I have no clue how to do this. Any help would be appreciated.

code:
<?php

include ("functions.php");

// Settings section ------------------------------


$filedir = "files/"; 				// The file folder
$columns = 1; 				        // Number of columns of files listed per row
$tablewidth = 600;                              // Table Width
$namecolumn = ($tablewidth / $columns) / 2;     // File Name Column Width
$datecolumn = $namecolumn / 2;                  // Date column width
$sizecolumn = $datecolumn;                      // File Size Column width
global $filename;
global $filename_sorted;

$i=0;
$j=0;
$k=0;
$m=0;

if(isset($_GET['st']))
{
  $st = $_GET['st'];
}
else
{
  $st = 1;
}

if(isset($_GET['order']))
{
  $order = "SORT_".$_GET['order'];
}
else
{
  $order = "SORT_ASC";
}  

// Table Title row -------------------------------

echo "<table width=\"$tablewidth\" cellpadding=\"2\" align=center><tr>";

echo "<link href='style.css' rel='stylesheet' type='text/css'>";

while ($k < $columns)
{
echo "<td width=$namecolumn align=center>";
echo "    <table border=0 cellpadding=0 cellspacing=0>";
echo "    <tr>";
echo "        <td rowspan=2><a href=\"index.php?st=1\"><u><b>Class Syllabus</b></u><a/>&nbsp;&nbsp;</td>";
echo "        <td><a href=\"index.php?st=1&order=ASC\"><img src=\"images/arrow_up.gif\" border=0></a></td>";
echo "    </tr>";
echo "    <tr>";
echo "        <td><a href=\"index.php?st=1&order=DESC\"><img src=\"images/arrow_down.gif\" border=0></a></td>";
echo "    </tr>";
echo "    </table></font>";
echo "</td>\n";
echo "<td width=$datecolumn align=center>";
echo "    <table border=0 cellpadding=0 cellspacing=0>";
echo "    <tr>";
echo "        <td rowspan=2 class='login'><a href=\"index.php?st=2\"><u><b>Date Uploaded</b></u><a/>&nbsp;&nbsp;</td>";
echo "        <td><a href=\"index.php?st=2&order=ASC\"><img src=\"images/arrow_up.gif\" border=0></a></td>";
echo "    </tr>";
echo "    <tr>";
echo "        <td><a href=\"index.php?st=2&order=DESC\"><img src=\"images/arrow_down.gif\" border=0></a></td>";
echo "    </tr>";
echo "    </table></font>";
echo "</td>\n";
echo "<td bgcolor=#C0C0C0 width=$sizecolumn align=center><font color=#000000>";
echo "    <table border=0 cellpadding=0 cellspacing=0>";
echo "    <tr>";
echo "        <td rowspan=2><a href=\"index.php?st=3\"><u><b>Download Size</b></u><a/>&nbsp;&nbsp;</td>";
echo "        <td><a href=\"index.php?st=3&order=ASC\"><img src=\"images/arrow_up.gif\" border=0></a></td>";
echo "    </tr>";
echo "    <tr>";
echo "        <td><a href=\"index.php?st=3&order=DESC\"><img src=\"images/arrow_down.gif\" border=0></a></td>";
echo "    </tr>";
echo "    </table></font>";
echo "</td>\n";

$k++;
}

echo "</tr><tr>";

$handle = opendir($filedir); 

while (false !==($file = readdir($handle)))
{ 
    if ($file != "." && $file != "..") 
    {
	//$filename[$i][1] = $file;
        //$filename[$i][2] = date ("m/d/y", filemtime($filedir.$file));
        //$filename[$i][3] = round(filesize($filedir.$file)/1024);
        $filename[$i][1] = $file;
        $filename[$i][2] = filemtime($filedir.$file); //date ("m/d/y", filemtime($filedir.$file));
        $filename[$i][3] = round(filesize($filedir.$file)/1024);
	++$i;
    }
}

closedir($handle);

// Sorting --------------------------------------------

$filename_sorted = csort($filename, $order, $st);

// End of Sorting -------------------------------------

while($m<(count($filename)))
{
 echo "<td bgcolor=#C0C0EF width=$namecolumn><a href=\"$filedir".$filename_sorted[$m][1]."\"><font color=#000000>".$filename_sorted[$m][1]."<font></a><br></td>\n";
        echo "<td bgcolor=#C0C0EF width=$datecolumn align=center><font color=#000000>";
	echo date("m/d/y",$filename_sorted[$m][2])."</font></td>";
        echo "<td bgcolor=#C0C0EF width=$sizecolumn  align=right><font color=#000000>";
	echo $filename_sorted[$m][3]." KB ";
        echo "</font></td>";
	++$j;
	  	if($j == $columns)
		{ 
			echo "</tr><tr>";
	  		$j = 0;
	  	}
 $m++;
}

echo "</tr></table><br><br><br>";


?>

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

IP logged posted posted 09-24-2007 14:32 Edit Quote

Are you wanting to use the same font and size for the entire document?

You have some font tags that you are probably wanting to get rid of right? Just guessing.

Let's take this section :

code:
while($m<(count($filename)))
{
 echo "<td bgcolor=#C0C0EF width=$namecolumn><a href=\"$filedir".$filename_sorted[$m][1]."\"><font color=#000000>".$filename_sorted[$m][1]."<font></a><br></td>\n";
        echo "<td bgcolor=#C0C0EF width=$datecolumn align=center><font color=#000000>";
	echo date("m/d/y",$filename_sorted[$m][2])."</font></td>";
        echo "<td bgcolor=#C0C0EF width=$sizecolumn  align=right><font color=#000000>";
	echo $filename_sorted[$m][3]." KB ";
        echo "</font></td>";
	++$j;
	  	if($j == $columns)
		{ 
			echo "</tr><tr>";
	  		$j = 0;
	  	}
 $m++;
}



Now for the first part

code:
echo "<td bgcolor=#C0C0EF width=$namecolumn><a href=\"$filedir".$filename_sorted[$m][1]."\"><font color=#000000>".$filename_sorted[$m][1]."<font></a><br></td>\n";



Give the td a class name, say "filename_sorted" and get rid of the <font> tag So now it would be :

code:
echo "<td bgcolor=#C0C0EF width=$namecolumn class="filename_sorted">
<a href=\"$filedir".$filename_sorted[$m][1]."\">".$filename_sorted[$m][1]."</a>
<br>
</td>\n";



Then in the <head> tag you would add a <style> section.

code:
<head>
  <style>
       .filename_sorted a{
            color:#000;
       }
  </style>
</head>



Now, any link inside of a class named "filename_sorted" will have the color #000.

Does that help or just confuse you more?

Might want to check out something like W3Schools to help learn CSS. To specify font names and colors and such, is not difficult to grasp.

Later,

C:\

K_C_
Obsessive-Compulsive (I) Inmate

From:
Insane since: Sep 2007

IP logged posted posted 09-24-2007 23:35 Edit Quote

Thank you for the reply !



That was definetly helpful. I've started some tutorials on CSS and you're right, it is pretty straightforward. I was thinking it would be too much to try and learn while trying to learn PHP but I can at least get the basics I need.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu