-3

I'm using a responsive pattern from Brad Frost's library to create an image grid (beta version here: http://yogeshsimpson.com/fry). I want to have three folders of images for the three portfolio categories that my client can just drop images into.

From there I think php is the right tool to get all the images from a folder, wrap in li and a tags and have them added to the ul. So on the homepage you see images from all three directories, and on the "lighting" page for example, you see only images from that directory, etc.

Again I'm assuming this is fairly easy to do with php, but it's a bit beyond my grasp. Any help would be appreciated. Much thanks.

4

1 回答 1

0

像这样的东西会起作用,从您希望列出文件的文件夹中运行它。

<?php

if ($handle = opendir('.')) {
   while (false !== ($file = readdir($handle)))
      {
          if ($file != "." && $file != "..")
      {

            $thelist .= '<li><a href="'.$file.'">'.$file.'</a>' . "<br>";

          }
       }
  closedir($handle);
  }       
?>
<P>List of files:</p>
<P><?=$thelist?></p>

或者:

<?php

// if running from your root and wish to list files from 'images' sub-folder
// use $dir = 'images';
$dir = '.'; // The directory containing the files.

// *.* will list all files. You can use *.jpg to list just JPG files, etc.
$ext = '*.*'; // will list ALL files
?> 

<ul> <?php foreach (glob($dir . '/*' . $ext) as $file) { ?> 
<li><a href="<?php echo $dir . "/" . $file ?>"><?php echo basename($file); ?></a></li>

<?php } ?> </ul>
于 2013-08-26T17:36:05.957 回答