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>";
?>

 

Link to comment
Share on other sites

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 "";
</

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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