if (!empty($nowUserId)) { //获取相册信息 $result = selectSql('albums', 'album_id,album_name,album_cover', 'user_id=' . $nowUserId); if ($result['state'] == 1) { $albumInfoArr = array(); while ($rows = mysql_fetch_assoc($result['msg'])) { $srcFile = $rows['album_cover'] == '' ? getAlbumCover($rows['album_id'], $defaultAlbumCover, $uploadImgPath) : $uploadImgPath . $rows['album_cover']; $dstFile = $rows['album_cover'] == '' ? getAlbumCover($rows['album_id'], $defaultAlbumCover, $uploadImgPath) : $thumImgPath . '75_75_' . $rows['album_cover']; thumbnails(iconv('utf-8', 'gb2312', $srcFile), iconv('utf-8', 'gb2312', $dstFile), 75, 75); $albumInfoArr[] = array('id' => $rows['album_id'], 'name' => $rows['album_name'], 'cover' => $dstFile, 'photoNum' => getPhotoNum($rows['album_id'])); } } if ($nowUserId == $userId) { $smarty->assign('isAuthor', true); } //读取相册的拥有者 $result = selectSql('users', 'user_name,user_avatar', 'user_id=' . $nowUserId); if ($result['state'] == 1) { $rows = mysql_fetch_assoc($result['msg']); $smarty->assign('authorName', $rows['user_name']); $smarty->assign('authorAvatar', $rows['user_avatar'] == '' ? $defaultAvatar : $avatarPath . $rows['user_avatar']); } $smarty->assign('authorId', $nowUserId); $smarty->assign('userId', $userId); $smarty->assign('userName', $userName); $smarty->assign('albumInfoArr', $albumInfoArr); $smarty->assign('cssFileName', 'albumList'); $smarty->display('albumList.tpl'); } ?>
$dstFile = iconv('utf-8', 'gb2312', $thumImgPath . '200_' . $matches[0]); thumbnails($srcFile, $dstFile, 200, ''); } } $smarty->assign('photoInfoArr', $photoInfoArr); } $smarty->assign('userId', $userId); $smarty->assign('userName', $userName); $smarty->assign('albumId', $albumId); $smarty->assign('albumCover', $albumCover); $smarty->assign('cssFileName', 'photoList'); $smarty->display('photoList.tpl'); } if (!empty($_POST['albumId']) && !empty($_POST['act']) && $_POST['act'] == 'delAlbum') { $albumId = $_POST['albumId']; $result = selectSql('photos', 'photo_id', 'album_id=' . $albumId); if ($result['state'] == 1) { //删除文件夹里的图片 while ($rows = mysql_fetch_array($result['msg'])) { deletePhoto($rows['photo_id']); } } //删除照片数据表中数据 $result = deleteSql('photos', 'album_id=' . $albumId); if ($result['state'] == 0) { echo json_encode(array('state' => 0, 'msg' => '删除失败')); return false; } //删除相册数据表中数据 $result = deleteSql('albums', 'album_id=' . $albumId); if ($result['state'] == 0) {
$subSubResult = selectSql('photos', 'photo_id,photo_name,upload_time', "album_id='{$albumId}' ORDER BY upload_time DESC"); if ($subSubResult['state'] == 1) { while ($subSubRows = mysql_fetch_assoc($subSubResult['msg'])) { $srcFile = iconv('utf-8', 'gb2312', $uploadImgPath . $subSubRows['photo_name']); $dstFile = iconv('utf-8', 'gb2312', $thumImgPath . '100_100_' . $subSubRows['photo_name']); thumbnails($srcFile, $dstFile, 100, 100); $friendPhotoInfoArr[] = array('photoId' => $subSubRows['photo_id'], 'photoName' => iconv('gb2312', 'utf-8', $dstFile)); } } } } $friendInfoArr[] = array('friendId' => $friendId, 'friendName' => $friendName, 'friendAvatar' => getAvatar($friendId, $defaultAvatar, $avatarPath), 'friendPhotoInfoArr' => $friendPhotoInfoArr); } } if ($nowUserId == $userId) { $smarty->assign('isAuthor', true); } //读取相册的拥有者 $result = selectSql('users', 'user_name', 'user_id=' . $nowUserId); if ($result['state'] == 1) { $rows = mysql_fetch_assoc($result['msg']); $smarty->assign('authorName', $rows['user_name']); } $smarty->assign('authorId', $nowUserId); $smarty->assign('friendInfoArr', $friendInfoArr); $smarty->assign('userAvatar', getAvatar($nowUserId, $defaultAvatar, $avatarPath)); $smarty->assign('userId', $userId); $smarty->assign('userName', $userName); $smarty->assign('cssFileName', 'friend'); $smarty->display('friend.tpl'); }
<?php require 'public.php'; set_time_limit(0); //防止下载超时 //附件下载 if (!empty($_GET['photoId'])) { $photoId = $_GET['photoId']; $result = selectSql('photos', 'photo_name', 'photo_id=' . $photoId); if ($result['state'] == 1) { $rows = mysql_fetch_assoc($result['msg']); $photoName = iconv('utf-8', 'gb2312', $rows['photo_name']); } //下载文件大小 $physicalpath = dirname(__FILE__) . '\\tmp\\' . $photoName; //文件物理位置 $filesize = filesize($physicalpath); //下载文件类型 $pattern = "/.+\\.([a-zA-Z]+)\$/"; preg_match_all($pattern, $photoName, $matches); header("Content-Type: application/force-download/" . $matches[1][0]); //强制弹出保存对话框 header("Pragma: no-cache"); // 缓存 header("Expires: 0"); header("Content-Transfer-Encoding: binary"); //发送数据方式 Header("Content-Length: " . $filesize); //文件大小 header('Content-Disposition: attachment; filename="' . $photoName . '"'); //文件名
<?php require 'public.php'; $nowUserId = $_GET['userId'] == '' ? $userId : $_GET['userId']; if (!empty($nowUserId)) { //读取用户资料 $userInfoArr = array(); $result = selectSql('users', 'user_name,user_avatar,user_nickName,user_sex,email,user_password,user_selfIntro', 'user_id=' . $nowUserId); if ($result['state'] == 1) { $rows = mysql_fetch_assoc($result['msg']); $userInfoArr = array('avatar' => $rows['user_avatar'] == '' ? $defaultAvatar : $avatarPath . $rows['user_avatar'], 'nickName' => $rows['user_nickName'] == '' ? '暂无' : $rows['user_nickName'], 'sex' => $rows['user_sex'] == '' ? '保密' : $rows['user_sex'], 'email' => $rows['email'] == '' ? '暂无' : $rows['email'], 'password' => $rows['user_password'], 'selfIntro' => $rows['user_selfIntro'] == '' ? '暂无' : $rows['user_selfIntro']); $smarty->assign('authorId', $nowUserId); $smarty->assign('authorName', $rows['user_name']); } if ($nowUserId == $userId) { $smarty->assign('isAuthor', true); } $smarty->assign('userInfoArr', $userInfoArr); $smarty->assign('userId', $userId); $smarty->assign('userName', $userName); $smarty->assign('cssFileName', 'account'); $smarty->display('account.tpl'); } ?>
echo json_encode(array('state' => 0, 'msg' => $tip)); } else { echo json_encode(array('state' => 1, 'msg' => '恭喜,全部图片上传成功')); } return false; } //清空列表时删除文件夹中图片 if (!empty($_POST['act']) && $_POST['act'] == 'remove' && !empty($_POST['fileNameArr'])) { $fileNameArr = $_POST['fileNameArr']; foreach ($fileNameArr as $val) { @unlink(dirname(__FILE__) . '\\tmp\\' . iconv('utf-8', 'gb2312', $val)); } echo json_encode(array('state' => 1, 'msg' => '清空列表成功')); return false; } $result = selectSql('albums', 'album_id,album_name', 'user_id=' . $userId); $albumInfoArr = array(); while ($rows = @mysql_fetch_assoc($result['msg'])) { $albumInfoArr[] = array('name' => $rows['album_name'], 'id' => $rows['album_id']); } $smarty->assign('albumInfoArr', $albumInfoArr); if (!empty($_GET['albumId'])) { $smarty->assign('uploadToSome', true); } if (isset($userId)) { $smarty->assign('userId', $userId); $smarty->assign('userName', $userName); $smarty->assign('cssFileName', 'upload'); $smarty->display('upload.tpl'); } ?>
function getAvatar($userId, $defaultAvatar, $avatarPath) { $result = selectSql('users', 'user_avatar', 'user_id=' . $userId); if ($result['state'] == 1) { $rows = mysql_fetch_assoc($result['msg']); return $rows['user_avatar'] == '' ? $defaultAvatar : $avatarPath . $rows['user_avatar']; } }
$photoInfoArr = array(); if ($uresult['state'] == 1) { while ($urows = mysql_fetch_assoc($uresult['msg'])) { $uuserId = $urows['user_id']; //推荐每个用户的5张照片信息 $result = selectSql('photos', 'photo_id,photo_name,photo_desc,album_id,upload_time', "user_id='{$uuserId}' ORDER BY upload_time DESC LIMIT 5"); if ($result['state'] === 1) { while ($rows = mysql_fetch_assoc($result['msg'])) { $albumId = $rows['album_id']; //根据相册id找到用户id $subResult = selectSql('albums', 'user_id', 'album_id=' . $albumId); if ($subResult['state'] == 1) { $subRows = mysql_fetch_assoc($subResult['msg']); $authorId = $subRows['user_id']; //根据用户id找到用户name $subSubResult = selectSql('users', 'user_name,user_avatar', 'user_id=' . $authorId); if ($subSubResult['state'] == 1) { $subSubRows = mysql_fetch_assoc($subSubResult['msg']); $authorName = $subSubRows['user_name']; $authorAvatar = $subSubRows['user_avatar'] == '' ? $defaultAvatar : $avatarPath . $subSubRows['user_avatar']; } } $pattern = "/(.+).(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF)\$/"; preg_match($pattern, $rows['photo_name'], $matches); $photoInfoArr[] = array('id' => $rows['photo_id'], 'name' => $matches[1], 'path' => $thumImgPath . '200_' . $matches[0], 'description' => $rows['photo_desc'], 'uploadTime' => $rows['upload_time'], 'authorName' => $authorName, 'authorId' => $authorId, 'authorAvatar' => $authorAvatar, 'photoComments' => getComments($rows['photo_id'], $defaultAvatar, $avatarPath)); //新上传的图片生成缩略图 $srcFile = iconv('utf-8', 'gb2312', $uploadImgPath . $matches[0]); $dstFile = iconv('utf-8', 'gb2312', $thumImgPath . '200_' . $matches[0]); thumbnails($srcFile, $dstFile, 200, ''); } }
} else { echo json_encode(array('state' => 0, 'msg' => '保存失败')); } } if (!empty($_GET['act'])) { $act = $_GET['act']; //上传头像 if (!empty($_FILES)) { $tempFile = $_FILES['newAvatar']['tmp_name']; $saveName = mktime() . '-' . $_FILES['newAvatar']['name']; $targetFile = $avatarPath . $saveName; if (!move_uploaded_file($tempFile, iconv('utf-8', 'gb2312', $targetFile))) { echo "<script>alert('保存失败');</script>"; } else { //读取出原来头像,删除 $result = selectSql('users', 'user_avatar', 'user_id=' . $userId); if ($result['state'] == 1) { $rows = mysql_fetch_assoc($result['msg']); @unlink(dirname(__FILE__) . '\\avatar\\' . iconv('utf-8', 'gb2312', $rows['user_avatar'])); } //保存数据到数据库 $result = updateSql('users', "user_avatar='{$saveName}'", 'user_id=' . $userId); if ($result['state'] == 1) { echo "<script>alert('保存成功');</script>"; } else { echo "<script>alert('保存失败');</script>"; } } } $smarty->assign('act', $act); $smarty->assign('userId', $userId);
<?php require 'public.php'; /*引用smarty模板类,已提取放到以public.php的文件中*/ if (!empty($_POST['userName']) && !empty($_POST['email']) && !empty($_POST['password']) && !empty($_POST['verificationCode'])) { $userName = $_POST['userName']; $email = $_POST['email']; $password = md5($_POST['password']); $verificationCode = $_POST['verificationCode']; $verificationCode = strtoupper($verificationCode); //把用户输入的验证码转化为大写 $registTime = date('Y-m-d H:i:s'); $result = selectSql('users', 'user_name', ''); $userNameArr = array(); while ($row = @mysql_fetch_assoc($result['msg'])) { $userNameArr[] = $row['user_name']; } if (in_array($userName, $userNameArr)) { echo json_encode(array('state' => 0, 'msg' => '该用户名已被占用.')); } else { $saveCode = $_SESSION['checkCode']; if ($saveCode == $verificationCode) { $result = insertSql('users', 'user_name,email,user_password,regist_time', "'{$userName}','{$email}','{$password}','{$registTime}'"); if ($result['state'] === 1) { echo json_encode(array('state' => 1, 'msg' => '恭喜,注册成功.')); $_SESSION['userName'] = $userName; $_SESSION['userId'] = mysql_insert_id(); } else { echo json_encode(array('state' => 0, 'msg' => '抱歉,注册失败.')); } } else {
if ($subSubResult['state'] == 1) { $subSubRows = mysql_fetch_assoc($subSubResult['msg']); $whoName = $subSubRows['user_name']; } $meAddWho[] = array('whoId' => $whoId, 'whoName' => $whoName, 'addTime' => $subRows['add_time'], 'whoAvatar' => getAvatar($whoId, $defaultAvatar, $avatarPath)); } } //我上传的图片 //朋友的所有相册 $mePhotoInfoArr = array(); $result = selectSql('albums', 'album_id', 'user_id=' . $nowUserId); if ($result['state'] == 1) { while ($rows = mysql_fetch_assoc($result['msg'])) { $albumId = $rows['album_id']; //朋友的所有照片 $subResult = selectSql('photos', 'photo_id,photo_name,upload_time', "album_id='{$albumId}' ORDER BY upload_time DESC"); if ($subResult['state'] == 1) { while ($subRows = mysql_fetch_assoc($subResult['msg'])) { $srcFile = iconv('utf-8', 'gb2312', $uploadImgPath . $subRows['photo_name']); $dstFile = iconv('utf-8', 'gb2312', $thumImgPath . '75_75_' . $subRows['photo_name']); thumbnails($srcFile, $dstFile, 75, 75); $mePhotoInfoArr[] = array('photoId' => $subRows['photo_id'], 'photoName' => iconv('gb2312', 'utf-8', $dstFile), 'uploadTime' => $subRows['upload_time']); } } } } $smarty->assign('mePhotoInfoArr', $mePhotoInfoArr); $smarty->assign('meAddWho', $meAddWho); $smarty->assign('authorId', $nowUserId); $smarty->assign('friendInfoArr', $friendInfoArr); $smarty->assign('otherUserInfoArr', $otherUserInfoArr);
<?php require 'public.php'; /*引用smarty模板类,已提取放到以public.php的文件中*/ if (!empty($_POST['userName']) && !empty($_POST['password'])) { $userName = $_POST['userName']; $password = md5($_POST['password']); $result = selectSql('users', 'user_id', "user_name='{$userName}' AND user_password='******'"); if ($result['state'] == 1) { if (mysql_num_rows($result['msg']) == 1) { $rows = mysql_fetch_assoc($result['msg']); $_SESSION['userName'] = $userName; $_SESSION['userId'] = $rows['user_id']; echo json_encode(array('state' => 1, 'msg' => '恭喜,登录成功.')); } else { echo json_encode(array('state' => 0, 'msg' => '抱歉,登录失败.')); } } else { echo json_encode(array('state' => 0, 'msg' => '抱歉,登录失败.')); } return false; } $smarty->assign('cssFileName', 'login'); $smarty->display('login.tpl'); ?>
if (isset($_POST['editName']) && !empty($_POST['photoId']) && !empty($_POST['act']) && $_POST['act'] == 'editPh') { $photoId = $_POST['photoId']; $editName = $_POST['editName']; $photoDesc = $_POST['photoDesc']; $result = updateSql('photos', "edit_name='{$editName}',photo_desc='{$photoDesc}'", 'photo_id=' . $photoId); if ($result['state'] == 1) { echo json_encode(array('state' => 1, 'msg' => '编辑成功.')); } else { echo json_encode(array('state' => 0, 'msg' => '编辑失败.')); } return false; } if (!empty($_POST['photoId']) && !empty($_POST['act']) && $_POST['act'] == 'setAlbumCover') { $photoId = $_POST['photoId']; //找出当前照片路径和所属相册id $result = selectSql('photos', 'photo_name,album_id', 'photo_id=' . $photoId); if ($result['state'] == 1) { $rows = mysql_fetch_assoc($result['msg']); $photoName = $rows['photo_name']; $albumId = $rows['album_id']; //更新相册封面 $result = updateSql('albums', "album_cover='{$photoName}'", 'album_id=' . $albumId); if ($result['state'] == 1) { echo json_encode(array('state' => 1, 'msg' => '设置成功.')); } else { echo json_encode(array('state' => 0, 'msg' => '设置失败.')); } } return false; } if (!empty($_POST['photoOwnerId']) && !empty($_POST['postText']) && !empty($_POST['act']) && $_POST['act'] == 'addComment') {