<?php
require ('authentication_member.php');
?>
<?php

/* 上传提交 */
/* 162100源码 - 162100.com */


if (POWER == 0) {
  err('<script>alert("提示：只有注册会员能上传，不过你可以选择链接形式");parent.closeSafe();</script>');
}
/*
if (!($_SERVER['HTTP_REFERER'] && strpos($_SERVER['HTTP_REFERER'], 'http://'.$_SERVER['HTTP_HOST']) === 0)) {
  err('<script>alert("跨域操作越权！");</script>');
}
*/

if (POWER <= 3) {
  if (strstr((string)$session[4], 'u') || strstr((string)$session[4], 'a') || strstr((string)$session[4], 't'))
    err('<script> alert("上传失败！你已被限制上传！请查看自己权限，或联系管理员"); parent.closeSafe();</script>');
  if ($session[3] < $web['up_start'])
    err('<script> alert("上传失败！系统限定用户上传等级分为'.$web['up_start'].'，您现在的等级分为'.$session[3].'"); parent.closeSafe();</script>');
}

$inis = ini_get_all();
$uploadmax = $inis['upload_max_filesize'];
/*
[global_value] => 2M
[local_value] => 2M
[access] => 6
*/
if (!is_array($_FILES['uploadfile']) || !$_FILES['uploadfile']['size']) {
  err('<script>alert("出现错误！请暂时停止上传。\n原因分析：\n1、上传数组参数为空 \n2、文件超过系统最大上传限量'.$uploadmax['global_value'].'（'.$uploadmax['local_value'].'）");parent.closeSafe();</script>');
}
if (POWER <= 4) {
  if ($_FILES['uploadfile']['size'] > $web['max_file_size'][$_REQUEST['in_id']]*1024) {
    err('<script> alert("对不起，上传的文件请小于'.$web['max_file_size'][$_REQUEST['in_id']].'KB"); parent.closeSafe();</script>');
  }
}
if (!$_REQUEST['in_id'] || $_REQUEST['in_id']<15 || $_REQUEST['in_id']>18) {
  err('<script>alert("出现错误！请暂时停止上传。文件类型参数缺失");parent.closeSafe();</script>');
}
if ($web['max_file_size'][$_REQUEST['in_id']] == 0) {
  err('<script> alert("系统设定为禁止上传"); parent.closeSafe();</script>');
}

switch ($_REQUEST['in_id']) {
  case 15:
    $reg = 'jpg|gif|png';
    break;
  case 16:
    $reg = 'gif|swf';//swf
    break;
  case 17:
    $reg = $web['_17_type'];
    break;
  default:
    $reg = $web['_18_type'];
    break;
}
if (!preg_match('/\.('.$reg.')$/i', $_FILES['uploadfile']['name'], $matches)) {
  err('<script>alert("提示！请选择一个有效的文件：允许的格式有（'.$reg.'）");parent.closeSafe();</script>');
}

//上传临时路径
if (!file_exists('__temp__')) {
  err('<script>alert("系统问题——数据库目录__temp__不存在！");parent.closeSafe();</script>');
}
if (!file_exists('__temp__/temp')) {
  err('<script>alert("系统问题——数据库临时上传目录__temp__/temp不存在！");parent.closeSafe();</script>');
}

$date = gmdate('Ymd', time() + (floatval($web['time_pos']) * 3600));
$time = gmdate('His', time() + (floatval($web['time_pos']) * 3600));
$upload_dir = '__temp__/temp';
$datetime = gmdate("Y-m-d H:i:s", time() + (floatval($web["time_pos"]) * 3600));


eval('@chmod(\'__temp__\', 0'.$web['chmod'].');');
eval('@chmod(\'__temp__/temp\', 0'.$web['chmod'].');');

$total = $n = 0;
if (!isset($sql['db_err'])) {
  db_conn();
}

if ($sql['db_err'] == '') {
  //求和信誉值
  $result = @mysql_query('SELECT SUM(money) AS total FROM '.$sql['pref'].''.$sql['data']['承载财务数据的表名'].' WHERE username="'.$session[0].'" AND type="1"', $db);
  $row = @mysql_fetch_assoc($result);
  $total = (float)$row['total'];
  unset($row);
  @mysql_free_result($result);
  //已经上传数
  $result = @mysql_query('SELECT COUNT(id) AS n FROM '.$sql['pref'].''.$sql['data']['承载上传数据的表名'].' WHERE username="'.$session[0].'" AND date LIKE "'.$datetime.'%" AND title NOT LIKE "face-%" AND title NOT LIKE "credit-%"', $db);
  $row = @mysql_fetch_assoc($result);
  $n = (float)$row['n'];
  unset($row);
  @mysql_free_result($result);
}
@mysql_close();

@ require ('inc/function/up_mx.php');
$up_mx = up_mx(abs($session[3]), $total);
if ($up_mx != -1 && (POWER <= 1)) {
  if ($n >= $up_mx) {
    err('<script> alert("对不起，您每日最多只能上传'.$up_mx.'个文件。不过在修改该文时你可更换图片"); parent.closeSafe();</script>');
  }
}

if (POWER != 5) {
if ($fp = @fopen($_FILES['uploadfile']['tmp_name'], 'rb')) {
  $img_contents = @fread($fp, $_FILES['uploadfile']['size']);
  @fclose($fp);
} else {
  $img_contents = @file_get_contents($_FILES['uploadfile']['tmp_name']);
}
if (preg_match('/<\?php|eval|POST|base64_decode|base64_encode/i', $img_contents, $m_err)) {
  err('<script> alert("提示！禁止提交。该文件含有禁止的代码'.str_replace('?', '\?', $m_err[0]).'。"); parent.closeSafe();</script>');
}
}
$upload_file = $date.$time.'-'.urlencode($session[0]).'--'.urlencode($_FILES['uploadfile']['type']).'.'.strtolower($matches[1]);

if (@move_uploaded_file($_FILES['uploadfile']['tmp_name'], $upload_dir.'/'.$upload_file)) {
  if ($web['water'] == 1 && @extension_loaded('gd')) { //加水印
    require ('inc/function/img.php');
    run_img_watermark($upload_dir.'/'.$upload_file, $web['pic_markwords'], $web['pic_quality']); //处理水印
  }
  $n++;
  err('
  <script language="javascript" type="text/javascript">
  <!--
  try{
    window.parent.insertFile("'.$_GET['pathUrl'].''.str_replace('%2F', '/', urlencode($upload_dir.'/'.$upload_file)).'","'.$_REQUEST['in_id'].'");
    //window.parent.insertFile("'.$_GET['pathUrl'].''.str_replace('%2F', '/', urlencode($upload_dir.'/'.urlencode($upload_file))).'","'.$_REQUEST['in_id'].'");
    alert("上传成功！'.($up_mx != -1 && (POWER <= 1) ? '\n您已经上传了'.$n.'条，还可以上传'.($up_mx - $n).'条' : '').'");
  }catch(err){
    alert(err);
  }
  parent.closeSafe();
  -->
  </script>', 'ok');
} else {
  err('<script>alert("出现错误！请暂时停止上传");parent.closeSafe();</script>');
}


?>