⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.php

📁 一个很漂亮的相册系统
💻 PHP
字号:
<? 
/*
########################################
# inso http://www.shi8.com			   #
# 使用GD库自动创建缩略图               #
########################################
*/
	require_once 'config.php';
/*----------------------------------------------*/

$gentime = microtime();
$gentime = explode(' ',$gentime);
$gentime = $gentime[1] + $gentime[0];
$pg_start = $gentime;

/*----------------------------------------------*/

    $url = $_SERVER["PHP_SELF"]."?";      
    $start = ( isset($_GET["start"]) ) ? $_GET["start"] : 0; 
    $sortby = ( isset($_GET["sortby"]) ) ? $_GET["sortby"] : $df_sortby; 
    $ascdsc = ( isset($_GET["ascdsc"]) ) ? $_GET["ascdsc"] : $df_ascdsc; 
 
    $sfxs = array(".jpg",".jpeg",".png",".PNG", ".JPG",".JPEG");     
    $curdir = dirname(stripslashes($_SERVER["PATH_TRANSLATED"]));     
    $slash = ( strstr($curdir,"\\") ) ? "\\" : "/";    
    $thumbdir = $thumbdir;    
    $images = array(); 
     
    @ $handle = opendir($curdir); 
    if ( !$handle ) { 
        error("无法打开目录!"); 
        exit; 
    } 
     
    while ( $file = readdir($handle) ) { 
        if ( isValid($file,$sfxs) ) { 
            $tmp = array(); 
            $tmp[0] = $file; 
            $tmp[1] = filemtime($file); 
            $tmp[2] = filesize($file); 
            array_push($images,$tmp); 

            if ( !file_exists($thumbdir.$slash.$file) ) { 
                createThumb($file); 
            } 
        } 
    } 

    usort($images,"sortme"); 
     
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 

<html> 
<head> 
    <title><? echo "$names";?> <? echo "$version";?>--Powered by inso (www.shi8.com)</title> 
	<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
	<script language='JavaScript' src='common.js'></script>
	<link rel='stylesheet' type='text/css' href='styles.css'>
</head> 
<body> 

<h3 align="center"><? echo "$names";?></h3> 
<? 

    $k = $start; 
    $n = count($images); 
    $ord = "&sortby=".$sortby."&ascdsc=".$ascdsc; 
    if ( $start > 0 ) { 
        $pn = $start - $rows*$cols; 
        $prev = '<a href="'.$url.$ord.'&start='.$pn.'">上一页</a>'; 
    } else { 
        $prev = "前一页"; 
    } 
    if ( $start + $rows*$cols < $n) { 
        $nn = $start + $rows*$cols; 
        $next = '<a href="'.$url.$ord.'&start='.$nn.'">下一页</a>'; 
    } else { 
        $next = "下一页"; 
    } 
    if ( $n-$k < $rows*$cols ) { 
        $rows = ceil(($n-$k)/$cols); 
    } 
?> 

<table border="0" align="center" width="<?=$cols*$maxw*1.4?>"> 
    <tr> 
        <td colspan="<?=$cols?>" align="center"> 
            <form name="f" action="<?=$_SERVER["PHP_SELF"]?>" 
method="GET"> 
            <input name="start" type="hidden" value="<?=$start?>"> 
            分类方式 
            <select name="sortby"> 
                <option value="-1">-- 分类方式 --</option> 
                <option value="date"<? if ($sortby=="date") echo " 
SELECTED"?>>日期</option> 
                <option value="size"<? if ($sortby=="size") echo " 
SELECTED"?>>大小</option> 
                <option value="name"<? if ($sortby=="name") echo " 
SELECTED"?>>名称</option> 
            </select> 
            <input name="ascdsc" value="ASC" type="radio"<? if 
($ascdsc=="ASC") echo " CHECKED"?>>升序 
            <input name="ascdsc" value="DESC" type="radio"<? if 
($ascdsc=="DESC") echo " CHECKED"?>>降序 
            <input type="submit" value="重排序"> 
            </form><br /> IP总量:<font color="green"><? include("counter.php");?></font>个 | 当前在线:<font color="green"><? include "online.php";?></font>位访客
        </td> 
    </tr> 
    <tr> 
        <td colspan="<?=$cols?>"><hr></td> 
    </tr> 
    <tr> 
        <td colspan="<?=$cols?>"> 
            <table width="100%"> 
                <tr> 
                    <td><?=$prev?></td> 
                    <td align="right"><?=$next?></td> 
                </tr> 
            </table> 
        </td> 
    </tr> 
<? 
    for ( $i=0; $i<$rows; $i++ ) { 
?> 
    <tr> 
<? 
        for ( $j=0; $j<$cols; $j++ ) { 
?> 
        <td class="img" width="<?=round(100/$cols)?>%"> 
<? 
            if ( $k < $n ) { 
?> 
            <a href="view.php?F=<?=$images[$k][0]?>" target="_blank"><img src=<?=$thumbdir."/".$images[$k][0]?> border=0 alt='<li>文件名:<b><?=$images[$k][0]?></b><li>文件大小:<font color=red><?=round($images[$k][2]/1024)?> </font>KB<li>创建日期:<font color=blue><?=date("Y年n月j日 H:i:s",$images[$k][1])?></font> ' vspace=2 style=filter:progid:DXImageTransform.Microsoft.Shadow(color=#000000,direction=135,strength=5)></a>
			<br /> 
			
<? 
            } else { 
?> 
            <img src="img/no.gif"  alt="暂无照片">
<? 
            } 
?> 
        </td> 
<? 
            $k++; 
        } 
?> 
    </tr> 
<? 
    } 
?> 
    <tr>
        <td colspan="<?=$cols?>"><hr></td> 
    </tr> 
</table> 
<table border="0" align="center" width="<?=$cols*$maxw*1.4?>"> 
    <tr> 
        <td  align="center"> 
<p align="right"><a href=form.php>上传图片</a><br />
<?
$gentime = microtime();
$gentime = explode(' ',$gentime);
$gentime = $gentime[1] + $gentime[0];
$pg_end = $gentime;
$totaltime = ($pg_end - $pg_start);
$showtime = number_format($totaltime, 5, '.', '');
echo("页面执行时间:" . $showtime . "秒");
?>
<br />
<a title="使用GD库创建缩略图<br />">inso相册 <? echo "$version";?></a><br />
&copy <a href="http://www.shi8.com" target="_target" title="照手册改的">inso汉化基地<a/>
</p>
		</td>
	</tr>
</table>
</body> 
</html> 



<? 
     

     
     
    function isValid($f,$a) { 
        $t = getSuffix($f); 
        return ( in_array($t,$a) ) ? true : false; 
    } 
     
    function getSuffix($f) { 
        $n = strrpos($f,"."); 
        return substr($f,$n,strlen($f)-$n); 
    } 
     
     
     
     
     
    function createThumb($f) { 

        global $maxw, $maxh, $curdir, $thumbdir, $slash; 
        $type = getSuffix($f); 

        if ($type==".png") { 
            $input = imagecreatefrompng($f); 
        } 
		else if ($type==".PNG") { 
            $input = imagecreatefrompng($f); 
        } 
		else { 
            $input = imagecreatefromjpeg($f); 
        } 
        if ( !$input ) { 
            error("无效图片格式"); 
            return false; 
        } 

        $tmp = getimagesize($f); 
        if ( !$tmp ) { 
            error("无法获得图片大小"); 
            return false; 
        } 

        $w = ($tmp[0]>$maxw) ? $maxw : $tmp[0]; 

        $h = $tmp[1] * ($maxw/$tmp[0]); 
        if ( $h>$maxh ) { 
            $h = $maxh; 
            $w = $tmp[0] * ($maxh/$tmp[1]); 
        } 

        @ $output = imagecreate($w,$h);//for GD 1.X
		//@ $output = imagecreatetruecolor($w,$h); //for GD 2.X
        if ( !$output ) { 
            error("无法生成缩略图"); 
            return false; 
        } 

        imagecopyresized( $output,$input, 0,0, 0,0, $w,$h, $tmp[0],$tmp[1] ); 
        $newfile = $thumbdir.$slash.$f; 

        if ( $type == ".png" ) { 
            imagepng($output,$newfile); 
			}
		else if ($type==".PNG") { 
            imagepng($output,$newfile);
         
        } else { 
            imagejpeg($output,$newfile); 
        } 
    } 
     
     
     
    function sortme($a,$b) { 

        global $sortby, $ascdsc; 
        if ( $sortby == "name" ) { 
            $n = 0; 
        } elseif ( $sortby == "date" ) { 
            $n = 1; 
        } elseif ( $sortby == "size" ) { 
            $n = 2; 
        } 
        $m = ( $ascdsc == "ASC" ) ? 1 : -1; 
        if ( $a[$n] == $b[$n] ) return 0; 
        return ($a[$n] > $b[$n]) ? $m : -1*$m; 
    } 
     
     
     
    function error($str) { 
        echo '<div style="background-color:#ffffff;color:#660000;font- 
weight:bold">'.$str.'</div>'; 
    } 
     
     
?> 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -