Jump to content


displaying files from a directory HELP


4 replies to this topic

#1 level9designs

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 25 June 2008 - 07:52 PM

Hello,

I'm trying to find the code to pull images files from a directory then display them in a multi-column table.

Such as:

img1 img2
img3 img4

ect ect

I've figured out who to do this with mysql, but can't get it to work from the directory, any ideas?

#2 derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 341 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 25 June 2008 - 08:31 PM

<?php

if ($handle = opendir('.')) {

while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file<br>\n";
}
}

}

?>

maybe you can figure it out from there. obveously you would replace . with the directory of choice.

#3 level9designs

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 25 June 2008 - 08:46 PM

I'm not quite sure how to display multi-column rows with the code you provided. Could you go a little more into detail?

#4 derek.sullivan

    Jedi In Training

  • Members
  • PipPip
  • 341 posts
  • Gender:Male
  • Location:Georgia
  • Interests:preaching, programming, music, friends, outdoors, moves, books

Posted 25 June 2008 - 10:21 PM

Okay try to using the tables.

#5 level9designs

    Young Padawan

  • Members
  • Pip
  • 9 posts

Posted 25 June 2008 - 11:09 PM

Ended up coming up with this code

<?php
$path= '/xxx/xxx/xxx';
$handle = opendir ($path);
$columns = 6;

$num_rows = count(glob($path . "*"));
echo "<TABLE border=\"0\" align\"center\">\n";

for($i = 0; $i < $num_rows; $i++) {
   $file = readdir($handle);
	if($i % $columns == 0) {
		echo "<TR>\n";
	}
	echo "<TD>".$file."</TD>\n";
	if(($i % $columns) == ($columns - 1) || ($i + 1) == $num_rows) {
		echo "</TR>\n";
	}
	
}
echo "</TABLE>\n";

?>






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users