<?
    max = 160; //max height & width
    maxCols = 3;
    path = "my/date/"; //the directory ya want to show
    AutorisedImageType = array ("jpg", "jpeg"); //image types
?>
----------------------------------------------------------------------------------------------------------

<?
   // Open path
   p = opendir(path);
   while (false !== (filename = readdir(p))) {
       filesArray[] = filename;
   }

   // Display and resize
   foreach (filesArray as images) {
  
       ext = substr(images, strpos(images, ".")+1, strlen(images));
      
       if( in_array(ext, AutorisedImageType) ) {

           list(width, height, type, attr) = @getimagesize( path.images );

            xRatio = max / width;
            yRatio = max / height;
           
            if ( (width <= max) && (height <= max) ) {
              newWidth = width;
              newHeight = height;
            }
            else if ((xRatio * height) < max) {
              newHeight = ceil(xRatio * height);
              newWidth = max;
            }
            else {
              newWidth = ceil(yRatio * width);
              newHeight = max;
            }
          
           if(i == maxCols) {
               echo "</tr><tr>";
               i = 0;
           }
           echo "<td align='center' valign='baseline' width='max' height='max'>
     <a href='".path.images."' target='_blank'><img src='".path.images."' width='newWidth' height='newHeight' border='0'></a>
     <br/>點擊看原圖</td>";
           i++;
       }
   }
              if(i <= 0) { //補充 :資料夾內無指定檔案
               echo "<td align='center' valign='middle'><font size='5' >暫無檔案</font></td>";
               i = 0;}

?>

-----------
參考PHP:readdir
本程式不能讀取子資料夾

文章標籤
全站熱搜
創作者介紹
創作者 琉璃鯨魚 的頭像
琉璃鯨魚

琉璃鯨魚

琉璃鯨魚 發表在 痞客邦 留言(0) 人氣(101)