showmessage('category_size_error'); } if (!empty($_POST['domain'])) { if (substr($_POST['domain'], 0, 7) != 'http://') { showmessage('category_domain_error'); } } $subcatidarr = array(); if (!empty($_POST['subcatid'])) { $subcatidarr = $_POST['subcatid']; } $newfilearr = array('file' => '', 'thumb' => ''); if (!empty($_FILES['icon'])) { $filearr = $_FILES['icon']; include_once S_ROOT . './function/upload.func.php'; $newfilearr = savelocalfile($filearr); } $setsqlarr = array('upid' => intval($_POST['upid']), 'name' => $_POST['name'], 'note' => trim($_POST['note']), 'tpl' => trim($_POST['tpl']), 'viewtpl' => trim($_POST['viewtpl']), 'displayorder' => intval($_POST['displayorder']), 'url' => trim($_POST['url']), 'htmlpath' => trim(shtmlspecialchars($_POST['htmlpath'])), 'domain' => trim($_POST['domain']), 'perpage' => empty($_POST['perpage']) ? 20 : intval($_POST['perpage']), 'prehtml' => trim($_POST['prehtml']), 'ischannel' => 0); if (!empty($newfilearr['file'])) { $setsqlarr['image'] = $newfilearr['file']; } if (!empty($newfilearr['thumb'])) { $setsqlarr['thumb'] = $newfilearr['thumb']; } if ($_POST['catid']) { //UPDATE $query = $_SGLOBAL['db']->query("SELECT * FROM " . tname('categories') . " WHERE catid='{$_POST['catid']}'"); $thecat = $_SGLOBAL['db']->fetch_array($query); if (!empty($_POST['icon_delete'])) { $setsqlarr['thumb'] = ''; $setsqlarr['image'] = '';
function uploadfile($valuearr, $mid = 0, $itemid = 0, $havethumb = 1, $width = 100, $height = 100) { global $_SGLOBAL; $setsqlarr = array(); $hash = getmodelhash($mid, $itemid); if (!empty($valuearr)) { foreach ($valuearr as $value) { if (preg_match("/^(img|flash|file)\$/i", $value['formtype'])) { $filearr = $_FILES[$value['fieldname']]; if (!empty($filearr['name'])) { $setsqlarr[$value['fieldname']] = array('fieldcomment' => $value['fieldcomment'], 'filepath' => '', 'error' => '', 'aid' => ''); if (empty($filearr['size']) || empty($filearr['tmp_name'])) { //获取上传文件大小失败,请选择其他文件上传 $setsqlarr[$value['fieldname']]['error'] = modelmsg('get_upload_size_error'); break; } $fileext = fileext($filearr['name']); $newfilearr = savelocalfile($filearr, array($width, $height), '', $havethumb); //上传 if ($value['formtype'] == 'img') { $attachinfo = @getimagesize(A_DIR . '/' . $newfilearr['file']); if (empty($attachinfo) || $attachinfo[2] < 1 && $attachinfo[2] > 3) { $setsqlarr[$value['fieldname']]['error'] = modelmsg('get_upload_size_error'); @unlink(A_DIR . '/' . $newfilearr['file']); if ($newfilearr['thumb'] != $newfilearr['file']) { @unlink(A_DIR . '/' . $newfilearr['thumb']); } break; } } if (empty($newfilearr['file'])) { //上传文件失败,请您稍后尝试重新上传 $setsqlarr[$value['fieldname']]['error'] = modelmsg('upload_error'); break; } //数据库 $insertsqlarr = array('uid' => $_SGLOBAL['supe_uid'], 'dateline' => $_SGLOBAL['timestamp'], 'filename' => saddslashes($filearr['name']), 'subject' => $value['fieldname'], 'attachtype' => $fileext, 'isimage' => in_array($fileext, array('jpg', 'jpeg', 'gif', 'png')) ? 1 : 0, 'size' => $filearr['size'], 'filepath' => $newfilearr['file'], 'thumbpath' => $newfilearr['thumb'], 'hash' => $hash); $aid = inserttable('attachments', $insertsqlarr, 1); $setsqlarr[$value['fieldname']]['filepath'] = $value['formtype'] != 'file' ? $newfilearr['file'] : $aid; $setsqlarr[$value['fieldname']]['aid'] = $aid; } } } } return $setsqlarr; }
if (empty($allowtypearr[$fileext])) { continue; } if ($filearr['size'] > $allowtypearr[$fileext]['maxsize']) { continue; } } $attachsize = $attachsize + $filearr['size']; //缩略图 if (!empty($_POST['thumb'][$i]) && !empty($_SCONFIG['thumbarray'][$_POST['thumb'][$i]])) { $thumbarr = $_SCONFIG['thumbarray'][$_POST['thumb'][$i]]; } else { $thumbarr = array($_POST['thumbwidth'], $_POST['thumbheight']); } //上传 $newfilearr = savelocalfile($filearr, $thumbarr); if (empty($newfilearr['file'])) { continue; } if (!is_array($_POST['picname'])) { showresult($blang['unable_to_complete_this_craft']); } //数据库 $insertsqlarr = array('uid' => $uid, 'dateline' => $_SGLOBAL['timestamp'], 'filename' => saddslashes($filearr['name']), 'subject' => trim(shtmlspecialchars($_POST['picname'][$i])), 'attachtype' => $fileext, 'isimage' => in_array($fileext, array('jpg', 'jpeg', 'gif', 'png')) ? 1 : 0, 'size' => $filearr['size'], 'filepath' => $newfilearr['file'], 'thumbpath' => $newfilearr['thumb'], 'hash' => $hash); inserttable('attachments', $insertsqlarr); $attachsize = $attachsize + $filearr['size']; $okcount++; } if ($okcount) { } else { showresult($blang['upload_other_space']);