1

我正在尝试改进我网站的管理员面板。我需要预览缩略图文件夹中的图像,这样当我使用缩略图获取新闻时,我不必第二次上传图像。我找到了一个很棒的脚本,但我无法读取目录错误。这是脚本:

<?php
  // filetypes to display
  $imagetypes = array("image/jpeg", "image/gif", "image/png");

  // Original PHP code by Chirp Internet: www.chirp.com.au
  // Please acknowledge use of this code by including this header.

  function getImages($dir)
  {
    global $imagetypes;

    // array to hold return value
    $retval = array();

    // add trailing slash if missing
    if(substr($dir, -1) != "/") $dir .= "/";

    // full server path to directory
    $fulldir = "{$_SERVER['DOCUMENT_ROOT']}/$dir";

    $d = @dir($fulldir) or die("getImages: Failed opening directory $dir for reading");
    while(false !== ($entry = $d->read())) {
      // skip hidden files
      if($entry[0] == ".") continue;

      // check for image files
      $f = escapeshellarg("$fulldir$entry");
      $mimetype = trim(`file -bi $f`);
      foreach($imagetypes as $valid_type) {
        if(preg_match("@^{$valid_type}@", $mimetype)) {
          $retval[] = array(
           'file' => "/$dir$entry",
           'size' => getimagesize("$fulldir$entry")
          );
          break;
        }
      }
    }
    $d->close();

    return $retval;
  }

  // fetch image details
  $images = getImages("../images/thumbnails");

  // display on page
  foreach($images as $img) {
    echo "<div class=\"photo\">";
    echo "<img src=\"{$img['file']}\" {$img['size'][3]} alt=\"\"><br>\n";
    // display image file name as link
    echo "<a href=\"{$img['file']}\">",basename($img['file']),"</a><br>\n";
    // display image dimenstions
    echo "({$img['size'][0]} x {$img['size'][1]} pixels)<br>\n";
    // display mime_type
    echo $img['size']['mime'];
    echo "</div>\n";
  }
?>

如果有人可以提供帮助,我真的很感激..

编辑:

<div style=" height: 200px; width: 600px; overflow: auto;">
<?PHP
 foreach(glob("../thumbnail/".'*') as $filename){
    echo "<div style=\"display:inline-table; font-size:10px; font-family:'Tahoma'; margin:5px;\">";
    echo "<img width=\"100px\" height=\"100px\" src=\"../thumbnail/$filename\"/>";
    echo "<br>".basename($filename) . "<br>";
    echo "</div>";
}
?>
</div>

这种方法效果很好。无需使用复杂的脚本。无论如何,有人可以告诉我如何检查显示的小于 100px x 100px 的图像吗?

4

1 回答 1

1
<?PHP
 foreach(glob("../thumbnail/".'*') as $filename){
    list($width, $height, $type, $attr) = getimagesize("../thumbnail/".$filename);
    if($width>=100 || $height >=100) continue;
    $rest = substr($filename, 3);
?>

应该这样做。。

于 2012-07-07T16:40:31.823 回答