<? <? // Display and resize list($width, $height, $type, $attr) = @getimagesize( $path.$images ); $xRatio = $max / $width;
$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;
}
foreach ($filesArray as $images) {
$ext = substr($images, strpos($images, ".")+1, strlen($images));
if( in_array($ext, $AutorisedImageType) ) {
$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
本程式不能讀取子資料夾
- Apr 08 Sun 2007 00:24
[P]縮略圖排列+點擊放大
close
全站熱搜
留言列表
發表留言