📄 album.php
字号:
<?php
/**************************************
模块:album
作者:lichail@hotmail.com
日期:2004.7
修改: 2005.2
***************************************/
require_once("config.inc.php");
$db=mysql_connect(HOST,USERNAME,PASSWORD);
$select=mysql_select_db(DATABASE,$db);
require_once("include/Language.inc.php");
$sys_lang = new Language("include/language/");
$sys_lang->setLanguage();
$lang_file = "album/language/".$sys_lang->getLang().".inc.php";
require_once($lang_file);
require_once("include/Vant.inc.php");
$tpl = & new Vant("templates/");
require_once("function.php");
$username = $_COOKIE['loginname'];
$tpl->set("loginname",$username);
$tpl->set("msg",$msg);
if ($username=='')
{
$tpl->set("msg",_NOGRANT);
$tpl->set("gourl","index.php");
$tpl->set("timesup","2000");
$tpl->set("main_middle","sysmsg.html");
$tpl->parse("main.html");
phpexit();
}
if(isAdmin($username))
{
session_start();
$username=$_SESSION['user'];
}
function phpexit()
{
global $db;
mysql_close($db);
exit;
}
function main()
{
global $username;
echo "<b>".$username."</b>"._PHOTO;
showphoto();
upload();
}
function upload(){
echo "<form action=\"album.php\" method=\"post\" ENCTYPE=\"multipart/form-data\">\n";
echo "<INPUT TYPE=\"hidden\" name=\"op\" value=\"upload\">\n";
echo "<INPUT TYPE=\"hidden\" name=\"name\" value=\"album\">\n";
echo "<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"200000\">\n";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#cccccc\">\n";
echo "<tr><td bgcolor=\"#ffffff\">"._UPLOAD."<input type=\"file\" size=\"40\" name=\"uploadfile1\">\n
<BR>"._ABOUTPIC."<input type=text name=about value=myphoto>";
/*
如果浏览照片收费,加上以下代码:
echo "<br>"._PHOTOSTAT;
echo "
<select name="price" id="price">
<option value="0" selected>不允许任何人查看</option>
<option value="1">允许任何人查看</option>
<option value="2">付费2点</option>
<option value="5">付费5点</option>
<option value="10">付费10点</option>
<option value="20">付费20点</option>
<option value="50">付费50点</option>
<option value="100">付费100点</option>
</select>";
*/
echo "<br><br>
<input type=\"submit\" value=\""._UPLOADPHOTO."\"><br><br>
"//<input type=\"reset\" value=\"Clear\">\n
._NOTICE
."</td></tr>\n";
echo "</table>\n";
echo "</form>\n";
}
function showphoto(){
global $db,$username;
echo "<SCRIPT type=\"text/javascript\">\n";
echo "<!--\n";
echo "var id;";
echo "function showpic(id) {\n";
echo "window.open('album.php?op=showpic&id='+id,'newwindow', 'height=500, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');";
echo "}\n";
echo "//-->\n";
echo "</SCRIPT>\n\n";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#cccccc\">\n"
."<tr><td bgcolor=\"#ffffff\">";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"\">\n";
echo "<tr align=\"center\">";
$array = mysql_fetch_array(mysql_query("select count(*) as picnum from user_album where username='$username'",$db));
$userpicnum = $array["picnum"];
$result = mysql_query("select * from user_album where username='$username'",$db);
$i=2;
while($rows = mysql_fetch_array($result)){
$owner = $rows["username"];
$img = $rows["path"];
$cover = $rows["fm"];
$id= $rows["ID"];
$name = $rows["name"];
//$price = $rows["price"];
$approved = $rows["approved"];
echo "<td>"
.$name."<br>"
."<a href=\"#\" onclick=showpic($id)>"
."<img src=\"$img\" border=\"0\" width=\"100\" height=\"140\">"
."</a>"
."<br>";
if($cover==1){
echo "<font color=\"red\">"._COVER."</font>";
if($userpicnum==1)
{
echo " | <a href=\"album.php?op=delphoto&f=$img\" >"._DELPHOTO."</a>";
if($approved==1)
echo " | <a href=\"album.php?op=close&id=$id\" >"._CLOSE."</a>";
elseif($approved==2)
echo " | <a href=\"album.php?op=open&id=$id\" >"._OPEN."</a>";
}
}
elseif($cover==0){
echo "<a href=\"album.php?op=setcover&id=$id\" >"._SETFIRST."</a> | ";
echo "<a href=\"album.php?op=delphoto&f=$img\" >"._DELPHOTO."</a>";
if($approved==1)
echo " | <a href=\"album.php?op=close&id=$id\" >"._CLOSE."</a>";
elseif($approved==2)
echo " | <a href=\"album.php?op=open&id=$id\" >"._OPEN."</a>";
}
/*
输出照片的状态:正在审查中/正常
*/
echo "<table><tr><td>"._PHOTOSTAT;
if($approved==0)echo _NOAPPROVED;
elseif($approved==1) echo _APPROVED;
elseif($approved==2) echo _CLOSED;
echo "</td></tr></table>";
//elseif($price==0)echo "关闭";
//elseif($price==1)echo "免费开放";
//else
//echo "级别:".$price."点";
//echo "</td></tr></table>";
/*
或者浏览照片所需的点数
*/
echo "<td>";
if(($i-1)%4==0)
echo "</tr><tr align=\"center\">";
$i++;
}
echo "</tr></table>";
echo "</td></tr></table>";
}
function open()
{
global $db,$select;
$id=$_GET['id'];
echo "<table><tr>";
$res = mysql_query("update user_album set approved='1' where ID='$id' and fm='0'",$db);
if($res)
echo "<td valign=\"top\" align=\"center\">"._SETOPENOK."<a href=\"album.php\">"._BACK."</a></td>";
echo "<tr></table>";
}
function close()
{
global $db,$select;
$id=$_GET['id'];
echo "<table><tr>";
$res = mysql_query("update user_album set approved='2' where ID='$id' and fm='0'",$db);
if($res)
echo "<td valign=\"top\" align=\"center\">"._SETCLOSEDOK."<a href=\"album.php\">"._BACK."</a></td>";
echo "<tr></table>";
}
function setcover(){
global $db,$select,$username;
mysql_query("update user_album set fm='0' where username='$username'",$db);
$id=$_GET['id'];
echo "<table><tr>";
$res = mysql_query("update user_album set fm='1' where ID='$id'",$db);
if($res)
echo "<td valign=\"top\" align=\"center\">"._SETOK."<a href=\"album.php\">"._BACK."</a></td>";
echo "<tr></table>";
}
function delphoto(){
global $db,$select,$username;
$f=$_GET['f'];
echo "<table><tr>";
if($f){
$result = mysql_query("select * from user_album where username='$username' and path='$f'",$db);
$info = mysql_fetch_array($result);
$pic = $info["path"];
$pid = $info["ID"];
@unlink($pic);
$res = mysql_query("delete from user_album where ID=$pid",$db);
if($res)
echo "<td valign=\"top\" align=\"center\">"._DELOK."<a href=\"album.php\">"._BACK."</a></td>";
}
echo "</tr></table>";
}
function savephoto(){
global $db,$select,$username,$op;
echo "<table><tr><td valign=\"top\" align=\"center\">";
$thumb_max_width = 400;
$thumb_max_height = 500;
$thumb_min_width = 160;
$thumb_min_height = 160;
//global $MAX_FILE_SIZE;
//global $uploadfile1;
//global $upload_dir;
//global $uploadfile1_type;
//global $uploadfile1_size;
//global $uploadfile1_name;
//$uploadfile1_type=strtolower($uploadfile1_type);
$uploadtemp1 = $_FILES['uploadfile1']['tmp_name'];
if(!$_FILES['uploadfile1']){
echo "No file specified or file outside guidelines.\n
<a href=javascript:history.back(-1)>Return to the form</a>
";
@unlink($uploadtemp1);
exit;
}
//if (is_uploaded_file($_FILES['uploadfile1'])) {
//if($_FILES['uploadfile1']['size']>$MAX_FILE_SIZE){
if($_FILES['uploadfile1']['error']==2){
echo "The size of your file is too big.\n
<a href=javascript:history.back(-1)>Return to the form</a>
";
@unlink($uploadtemp1);
exit;
}
if(($_FILES['uploadfile1']['type']=="image/pjpeg")||($_FILES['uploadfile1']['type']=="image/jpeg")){
//$image = imagecreatefromjpeg($uploadtemp1);
//$width = imagesx($image);
//$height = imagesy($image);
//echo $width."<br>".$height;
//if($width<$thumb_min_width||$height<$thumb_min_height){
//echo "The size of your photo must be too small.\n
// <a href=javascript:history.back(-1)>Return to the form</a>
// ";
//@unlink($uploadtemp1);
//exit;
//}
$array = mysql_fetch_array(mysql_query("select count(*) as picnum from user_album where username='$username'",$db));
$userpicnum = $array["picnum"];
if($userpicnum == 10){
echo "You can only have 10 photos.\n
<a href=javascript:history.back(-1)>Return to the form</a>
";//设置用户能上传的最大照片数
@unlink($uploadtemp1);
exit;
}
$savepath = "album/pic/";//照片存储的路径
$upfile = $savepath.$username."_".$userpicnum.".jpg";
if(@move_uploaded_file($uploadtemp1, $upfile))
{
$picnum = $userpicnum+1;
$pre = time();
$filename = $username."_".$picnum."_".$pre.".jpg";
$path2= $savepath.$filename;
create_thum($upfile,$thumb_max_width,$thumb_max_height,$path2);
$time=date("Y-m-d");
$fm = ($userpicnum == 0 ? "1":"0");
$about=$_POST['about'];
/*
浏览照片收费时的SQL语句
$str = "insert into user_album values (NULL,'$username','0','$time','$path2','$fm',0,'$about','$price')";
设置了浏览每张照片所需要的积分
*/
$str = "insert into user_album values (NULL,'$username','0','$time','$path2','$fm',0,'$about')";
$result = mysql_query($str,$db);
if($result){
echo " "._UPLOADIMAGESUCCEEDED." "."<a href=album.php>"._BACK."</a><br>";
@unlink($uploadtemp1);
//更新用户的积分
upPoint($_COOKIE['loginname'],"SavePhoto","");
}
else {
echo "SQL Erro:".$str;
@unlink($uploadtemp1);
}
@unlink($upfile);
}
}else{
echo "The type of your file must be jpg.\n
<a href=javascript:history.back(-1)>Return to the form</a>
";
@unlink($uploadtemp1);
exit;
}
//}
echo "</td></tr></table>";
}
function create_thum($im,$maxwidth,$maxheight,$name){
$image2=imagecreatefromjpeg($im);
$width = imagesx($image2);
$height = imagesy($image2);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth/$width;
$RESIZEWIDTH=true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight/$height;
$RESIZEHEIGHT=true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("imagecopyresampled")){
$newim = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newim, $image2, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = imagecreate($newwidth, $newheight);
imagecopyresized($newim, $image2, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
//ImageJpeg ($newim,$name);
$im = $newim;
}else{
//ImageJpeg ($image2,$name);
$im = $image2;
}
$di = $im;//imagecreatefromjpeg($im);
//$si = imagecreatefromjpeg("pic/lp.jpg");
$si = imagecreatefrompng("album/pic/lp.png");
$wd = imagesx($di);//$width;
$hd = imagesy($di);//$height;
$ws = imagesx($si);
$hs = imagesy($si);
$hy = ($hd-$hs);
imagecopy($di,$si,0,$hy,0,0,$ws,$hs);
imagejpeg($di,$name);
imagedestroy($si);
imagedestroy($di);
}
function showpic($id){
global $db,$username;
if(!$username)
exit("please login");
$result = mysql_query("select * from user_album where ID='$id'",$db);
$info = mysql_fetch_array($result);
$img = $info["path"];
$usr = $info["username"];
if($usr!=$username)
mysql_query("update user_album set click=click+1 where ID='$id'",$db);
echo '<script language="JavaScript">
document.oncontextmenu=new Function("event.returnValue=false;");
document.onselectstart=new Function("event.returnValue=false;");
</script>
<body leftMargin=0 topMargin=0>';
echo "<img src=\"$img\">";
echo "<br><br><center><button onclick=window.close()>Close window</button></center></body>";
}
if($op!="showpic")
{
$tpl->parse("header.html");
echo
'<table width="760" border="0" align="center">
<tr>
<td align="center">';
}
switch($op)
{
case "upload" :
savephoto();
break;
case "setcover" :
setcover();
break;
case "close":
close();
break;
case "open":
open();
break;
case "delphoto" :
delphoto();
break;
case "showpic":
showpic($id);
break;
default:
main();
break;
}
if($op!="showpic")
{
$tpl->parse("footer.html");
echo
'</td>
</tr>
</table>';
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -