public static function savefile($param = array()) { global $_G; require_once VI_ROOT . 'source/class/thumb.php'; require_once VI_ROOT . 'source/class/ftp.php'; if ($_G['setting']['global']['upload'] != 'on') { return FALSE; } $default = array('field' => 'file', 'model' => 'normal', 'crop' => NULL, 'thumb' => NULL, 'group' => NULL, 'index' => -1, 'absolute' => FALSE, 'account' => 'manager', 'filetype' => '*', 'remote' => $_G['setting']["attach"]["FTP_OPEN"] == 'true', 'watermark' => $_G['setting']['attach']['MARK_OPEN'] == 'true' ? VI_ROOT . $_G['setting']['attach']['MARK_FILE'] : NULL, 'position' => $_G['setting']['attach']['MARK_POSITION'], 'multiple' => $_G['setting']['attach']['MARK_MULTIPLE']); $param = array_merge($default, $param); //////////////////////// if ($param['index'] == -1) { $temp = $_FILES[$param['field']]; } else { $temp = array('name' => $_FILES[$param['field']]["name"][$param['index']], 'tmp_name' => $_FILES[$param['field']]["tmp_name"][$param['index']], 'size' => $_FILES[$param['field']]["size"][$param['index']], 'error' => $_FILES[$param['field']]["error"][$param['index']]); } //var_dump( $temp ); //上传出错 if (!isset($temp) || $temp['error']) { self::$error = $temp['error']; return FALSE; } //////////////////////// $data = self::checkfile($temp['name'], $param['filetype']); //未知格式 if ($data === FALSE) { return FALSE; } //源图信息 if ($data['type'] == 'image') { list($param['origin']['width'], $param['origin']['height']) = getimagesize($temp['tmp_name']); $width = $param['origin']['width']; $height = $param['origin']['height']; //裁切尺寸与原图尺寸一样时不裁切 if ($param['crop'] && $param['crop'][0] == $width && $param['crop'][1] == $height) { $param['crop'] = NULL; } } else { $param['origin'] = NULL; $width = $height = 0; } //水印信息 if ($param['watermark'] && file_exists($param['watermark'])) { list($param['water']['width'], $param['water']['height']) = getimagesize($param['watermark']); } else { $param['water'] = NULL; } $file = $param['remote'] ? self::stored_remote($temp['tmp_name'], $data, $param) : self::stored_locale($temp['tmp_name'], $data, $param); //////////////////////// //记录到最近(宽度,高度,本地文件名,上传文件名,扩展名,文件大小) self::$detail = array('width' => $width, 'height' => $height, 'name' => $temp['name'], 'file' => $file, 'extra' => $data['extra'], 'size' => $temp['size']); self::$error = 0; //////////////////////// if ($param['account'] == 'member') { $user = array('id' => $_G['member']['id'], 'name' => $_G['member']['username']); } else { $user = array('id' => $_G['manager']['id'], 'name' => $_G['manager']['account']); } //写入数据库 $sql = "INSERT INTO `sys:attach`(aid,account,name,input,dateline,type,size,ip,width,height,remote) values('" . $user['id'] . "','" . $user['name'] . "','" . $file . "','" . $param['field'] . "'," . time() . ",'" . $data['extra'] . "'," . $temp['size'] . ",'" . GetIP() . "',{$width},{$height}," . intval($param['remote']) . ")"; System::$db->execute($sql); //////////////////////// //绝对地址 if ($param['absolute'] && $param['remote'] == FALSE) { return substr_replace($file, VI_HOST, 0, strlen(VI_BASE)); } else { return $file; } }