function movetmpfile($attach, $targetfile) { forcemkdir(dirname($targetfile)); if (copy($attach['tmp_name'], $targetfile) || move_uploaded_file($attach['tmp_name'], $targetfile)) { return 1; } if (is_readable($attach['tmp_name'])) { $fp = fopen($attach['tmp_name'], 'rb'); flock($fp, 2); $attachedfile = fread($fp, $attach['size']); fclose($fp); $fp = fopen($targetfile, 'wb'); flock($fp, 2); if (fwrite($fp, $attachedfile)) { unlink($attach['tmp_name']); } fclose($fp); return 1; } return 0; }
function onedit() { $gid = intval($this->get[2]) ? $this->get[2] : $this->post['id']; if (isset($this->post['submit'])) { $title = $this->post['giftname']; $desrc = $this->post['giftdesrc']; $credit = intval($this->post['giftprice']); $imgname = strtolower($_FILES['imgurl']['name']); if ('' == $title || !$credit) { $message = '请正确填写礼品相关信息'; $type = 'errormsg'; include template('addgift', 'admin'); exit; } $type = substr(strrchr($imgname, '.'), 1); if (!empty($_FILES['imgurl']['tmp_name']) && !isimage($type)) { $message = '图片格式不支持,目前仅支持jpg、gif、png格式!'; $type = 'errormsg'; include template('addgift', 'admin'); exit; } $filepath = '/data/attach/giftimg/gift' . random(6, 0) . '.' . $type; forcemkdir(TIPASK_ROOT . '/data/attach/giftimg'); if (!empty($_FILES['imgurl']['tmp_name']) && !move_uploaded_file($_FILES['imgurl']['tmp_name'], TIPASK_ROOT . $filepath)) { $message = '服务器忙,请稍后再试!'; $type = 'errormsg'; include template('addgift', 'admin'); exit; } empty($_FILES['imgurl']['tmp_name']) && ($filepath = $this->post['imgpath']); $_ENV['gift']->update($title, $desrc, $filepath, $credit, $gid); $message = "修改成功!"; } $gift = $_ENV['gift']->get($gid); include template('addgift', 'admin'); }
/** * 后台修改专题 */ function onedit() { if (isset($this->post['submit'])) { $title = $this->post['title']; $desrc = $this->post['desc']; $tid = intval($this->post['id']); $imgname = strtolower($_FILES['image']['name']); if ('' == $title || '' == $desrc) { $this->ondefault('请完整填写专题相关参数!', 'errormsg'); exit; } if ($imgname) { $type = substr(strrchr($imgname, '.'), 1); if (!isimage($type)) { $this->ondefault('当前图片图片格式不支持,目前仅支持jpg、gif、png格式!', 'errormsg'); exit; } $filepath = '/data/attach/topic/topic' . random(6, 0) . '.' . $type; $upload_tmp_file = TIPASK_ROOT . '/data/tmp/topic_' . random(6, 0) . '.' . $type; forcemkdir(TIPASK_ROOT . '/data/attach/topic'); if (move_uploaded_file($_FILES['image']['tmp_name'], $upload_tmp_file)) { image_resize($upload_tmp_file, TIPASK_ROOT . $filepath, 270, 220); $_ENV['topic']->update($tid, $title, $desrc, $filepath); $this->ondefault('专题修改成功!'); } else { $this->ondefault('服务器忙,请稍后再试!'); } } else { $_ENV['topic']->update($tid, $title, $desrc); $this->ondefault('专题修改成功!'); } } else { $topic = $_ENV['topic']->get(intval($this->get[2])); include template("addtopic", 'admin'); } }
function forcemkdir($path) { if (!file_exists($path)) { forcemkdir(dirname($path)); mkdir($path, 0777); } }
if ($userinfo['gender'] == '女') { $gender = 0; } } $randpasswd = strtolower(random(6, 1)); $uid = add_user($userinfo['nickname'], $randpasswd, $gender, $token, $openid); $userid = $uid; if ($uid && $setting['qqlogin_avatar']) { $avatardir = "/data/avatar/"; $uid = sprintf("%09d", $uid); $dir1 = $avatardir . substr($uid, 0, 3); $dir2 = $dir1 . '/' . substr($uid, 3, 2); $dir3 = $dir2 . '/' . substr($uid, 5, 2); !is_dir(TIPASK_ROOT . $dir1) && forcemkdir(TIPASK_ROOT . $dir1); !is_dir(TIPASK_ROOT . $dir2) && forcemkdir(TIPASK_ROOT . $dir2); !is_dir(TIPASK_ROOT . $dir3) && forcemkdir(TIPASK_ROOT . $dir3); $smallimg = $dir3 . "/small_" . $uid . '.jpg'; get_remote_image($userinfo['figureurl_qq_2'], TIPASK_ROOT . $smallimg); $user = get_user($uid); $redirect = url("user/profile", 1); $subject = "恭喜您在" . $setting['site_name'] . "注册成功!"; $content = '您可以正常提问和回答了!您的登录用户名是 ' . $user['username'] . ',登录密码是 ' . $randpasswd . ',为了保证您的账号安全,请及时修改密码,完善个人信息!<br /><a href="' . $redirect . '">请点击此处完善个人信息</a>'; $db->query('INSERT INTO ' . DB_TABLEPRE . "message SET `from`='" . $setting['site_name'] . "' , `fromuid`=0 , `touid`={$userid} , `subject`='{$subject}' , `time`=" . time() . " , `content`='{$content}'"); refresh($user); header("Location:" . SITE_URL); exit; } $user = get_user($userid); $redirect = url("user/profile", 1); $subject = "恭喜您在" . $setting['site_name'] . "注册成功!"; $content = '您可以正常提问和回答了!您的登录用户名是 ' . $user['username'] . ',登录密码是 ' . $randpasswd . ',为了保证您的账号安全,请及时修改密码,完善个人信息!<br /><a href="' . $redirect . '">请点击此处完善个人信息</a>';
function onbackup() { set_time_limit(0); $filedir = TIPASK_ROOT . "/data/db_backup/"; if (!isset($this->post['backupsubmit']) && !isset($this->get[9])) { $sqlfilename = date("Ymd", $this->time) . "_" . random(8); $tables = $_ENV['db']->showtables(); forcemkdir($filedir); $filename = $_ENV['db']->get_sqlfile_list($filedir); include template('dbbackup', 'admin'); } else { $sqldump = ''; $type = isset($this->post['type']) ? $this->post['type'] : $this->get[2]; $sqlfilename = isset($this->post['sqlfilename']) ? $this->post['sqlfilename'] : rawurldecode($this->get[3]); $sizelimit = isset($this->post['sizelimit']) ? $this->post['sizelimit'] : intval($this->get[4]); $tableid = intval($this->get[5]); $startfrom = intval($this->get[6]); $volume = intval($this->get[7]) + 1; $compression = isset($this->post['compression']) ? $this->post['compression'] : intval($this->get[8]); $backupfilename = $filedir . $sqlfilename; $backupsubmit = 1; $tables = array(); if (substr(trim(ini_get('memory_limit')), 0, -1) < 32 && substr(trim(ini_get('memory_limit')), 0, -1) > 0) { @ini_set('memory_limit', '32M'); } if (!is_mem_available($sizelimit * 1024 * 3)) { $this->message($sizelimit . 'KB 大于PHP程序可用值,请设置较小分卷大小值', 'index.php?admin_db/backup'); } switch ($type) { case "full": $tables = $_ENV['db']->showtables(); break; case "stand": $tables = array(DB_TABLEPRE . "category", DB_TABLEPRE . "question", DB_TABLEPRE . "answer", DB_TABLEPRE . "user", DB_TABLEPRE . "setting"); break; case "min": $tables = array(DB_TABLEPRE . "question", DB_TABLEPRE . "answer"); break; case "custom": if (!(bool) $this->post['tables']) { $tables = $this->cache->read('backup_tables', '0'); } else { $tables = $this->post['tables']; $this->cache->write('backup_tables', $tables); } break; } if ($sizelimit < 512) { $this->message('文件大小限制不要小于512K', 'BACK'); } if (count($tables) == 0) { $this->message('请先选择数据表!', 'BACK'); } if (!file_exists($filedir)) { forcemkdir($filedir); } if (!iswriteable($filedir)) { $this->message('/data/db_backup 文件夹不可写!', 'index.php?admin_db-backup'); } if (in_array(DB_TABLEPRE . "usergroup", $tables)) { $num = array_search(DB_TABLEPRE . "usergroup", $tables); $tables[$num] = $tables[0]; $tables[0] = DB_TABLEPRE . "usergroup"; } if (in_array(DB_TABLEPRE . "user", $tables)) { $num = array_search(DB_TABLEPRE . "user", $tables); if ($tables[0] == DB_TABLEPRE . "usergroup") { $tables[$num] = $tables[1]; $tables[1] = DB_TABLEPRE . "user"; } else { $tables[$num] = $tables[0]; $tables[0] = DB_TABLEPRE . "user"; } } $complete = TRUE; for (; $complete && $tableid < count($tables) && strlen($sqldump) + 500 < $sizelimit * 1000; $tableid++) { $result = $_ENV['db']->sqldumptable($tables[$tableid], $complete, $sizelimit, $startfrom, strlen($sqldump)); $sqldump .= $result['tabledump']; $complete = $result['complete']; if ($complete) { $startfrom = 0; } else { $startfrom = $result['startfrom']; } } $dumpfile = $backupfilename . "_%s" . '.sql'; !$complete && $tableid--; if (trim($sqldump)) { $result = $_ENV['db']->write_to_sql($sqldump, $dumpfile, $volume); if (!$result) { $this->message('无法写入sql文件,请返回', 'BACK'); } else { $url = "index.php?admin_db/backup/{$type}/" . rawurlencode($sqlfilename) . "/{$sizelimit}/{$tableid}/{$startfrom}/{$volume}/{$compression}/{$backupsubmit}"; $this->message("<image src='css/default/loading.gif'><br />第 " . $volume . ' 个文件已经完成!正在进入下一个备份!' . "<script type=\"text/javascript\">setTimeout(\"window.location.replace('{$url}');\", 2000);</script>", 'BACK'); } } else { $volume--; if ($compression && is_mem_available($sizelimit * 1024 * 3 * $volume)) { $_ENV['db']->write_to_zip($backupfilename, $dumpfile, $volume); } $this->cache->remove('backup_tables'); $this->message('数据备份成功!', 'admin_db/backup'); } } }
function oneditimg() { if (isset($_FILES["userimage"])) { $uid = intval($this->get[2]); $avatardir = "/data/avatar/"; $extname = extname($_FILES["userimage"]["name"]); if (!isimage($extname)) { exit('type_error'); } $upload_tmp_file = TIPASK_ROOT . '/data/tmp/user_avatar_' . $uid . '.' . $extname; $uid = abs($uid); $uid = sprintf("%09d", $uid); $dir1 = $avatardir . substr($uid, 0, 3); $dir2 = $dir1 . '/' . substr($uid, 3, 2); $dir3 = $dir2 . '/' . substr($uid, 5, 2); !is_dir(TIPASK_ROOT . $dir1) && forcemkdir(TIPASK_ROOT . $dir1); !is_dir(TIPASK_ROOT . $dir2) && forcemkdir(TIPASK_ROOT . $dir2); !is_dir(TIPASK_ROOT . $dir3) && forcemkdir(TIPASK_ROOT . $dir3); $smallimg = $dir3 . "/small_" . $uid . '.' . $extname; if (move_uploaded_file($_FILES["userimage"]["tmp_name"], $upload_tmp_file)) { $avatar_dir = glob(TIPASK_ROOT . $dir3 . "/small_{$uid}.*"); foreach ($avatar_dir as $imgfile) { if (strtolower($extname) != extname($imgfile)) { unlink($imgfile); } } if (image_resize($upload_tmp_file, TIPASK_ROOT . $smallimg, 80, 80)) { echo 'ok'; } } } else { if ($this->setting["ucenter_open"]) { $this->load('ucenter'); $imgstr = $_ENV['ucenter']->set_avatar($this->user['uid']); } include template("editimg"); } }
function uploadfile($upname, $targetFile) { $sucess = 0; $targetDir = dirname($targetFile); forcemkdir($targetDir); if (@copy($_FILES[$upname]['tmp_name'], $targetDir) || @move_uploaded_file($_FILES[$upname]['tmp_name'], $targetFile)) { $sucess = 1; } if (0 == $sucess && @is_readable($_FILES[$upname]['tmp_name'])) { @($fp = fopen($_FILES[$upname]['tmp_name'], 'rb')); @flock($fp, 2); @($file = fread($fp, $_FILES[$upname]['size'])); @fclose($fp); @($fp = fopen($targetFile, 'wb')); @flock($fp, 2); if (@fwrite($fp, $file)) { @unlink($_FILES[$upname]['tmp_name']); $sucess = 1; } @fclose($fp); } return $sucess; }