Jump to content

get filenames from directory and display each in a cell no wider than 5 columns


joshd963

Recommended Posts

Hi guys. Just a quick PHP question. I have a script running that gets the files from a directory. There is then a switch function that decides what to do with the file, ie... if it is a PNG... DO THIS.. if it is a docx... DO THIS.. etc.

And i want each file to be in a different cell on the table. The table can be longer wider than 5 columns (however it can be as high as it wants). I currently have this bit working... but instead of one item in each cell... it is displaying every item in each cell. Any ideas Chaps? Here is my code  ;D

Many thanks in advance if you could possibly help..

echo "<table><tr>";
$count = count(glob("../../shared/files/*.*", GLOB_BRACE));
for($i=1; $i <= $count; $i++) 
{ 
///
echo "<td>";
///
if ($handle = opendir('../../shared/files/')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {

$break = pathinfo($file);
$b = $break['extension'];

switch (@$break[extension]) { 
case 'bmp' : 
    echo 'A BMP<br>'; 
    break;

case 'png' :
    echo 'A PNG<br>';
    break;

case  'doc' :
case 'docx' :
    echo 'A DOC OR DOCX<br>';
    break;
             
default:
     echo 'FILE NOT RECOGNISED<br>';

}
}
}
    closedir($handle);
}

///

echo "</td>";
///

if($i % 3 == 0) 
    echo "</tr><tr>"; 
} 
echo "</tr></table>";
?>

 

This,

if($i % 3 == 0) 
    echo ""; 
} 

Should be at the BEGINNING of your loop, not the end.

 

I mean this

echo "</pre>
<table>";
$count = count(glob("../../shared/files/*.*", GLOB_BRACE));
for($i=1; $i { 
/// Put it here if($i % 3 == 0) 
    echo ""; 
} 
///// echo "";
</

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.