public function addMaterial() { if ($_FILES['Filedata']) { if ($_FILES['Filedata']['error']) { return false; } else { /*验证格式*/ include_once CUR_CONF_PATH . 'lib/cache.class.php'; $this->cache = new cache(); $gMaterialTpye = $this->cache->check_cache('material_type.cache.php'); $info = array(); $typetmp = explode('.', $_FILES['Filedata']['name']); $filetype = strtolower($typetmp[count($typetmp) - 1]); $info['type'] = $filetype; $type = ''; foreach ($gMaterialTpye as $k => $v) { if (in_array($filetype, array_keys($v))) { $type = $k; break; } } if (empty($type)) { return false; } /*验证大小*/ $max_size = UPLOAD_FILE_LIMIT * 1024 * 1024; if ($_FILES['Filedata']['size'] > $max_size) { return false; } $info['cid'] = intval($this->input['cid']); $info['catid'] = intval($this->input['catid']); $info['bundle_id'] = urldecode($this->input['app_bundle']); $info['mid'] = urldecode($this->input['module_bundle']); $info['user_id'] = intval($this->input['user_id']); $info['user_name'] = urldecode($this->input['user_name']); $info['client_id'] = intval($this->input['client_id']); $info['client_name'] = urldecode($this->input['client_name']); //存放的路径 $info['filepath'] = date('Y') . '/' . date('m') . '/'; $info['name'] = urldecode($_FILES['Filedata']['name']); $tmp_filename = date('YmdHis') . hg_generate_user_salt(4); $info['filename'] = $tmp_filename . '.' . $info['type']; $path = hg_getimg_dir() . app_to_dir($info['bundle_id'], $type) . $info['filepath']; $info['mark'] = $type; //如果附件为img图片类型的则 获取水印设置 if ($info['mark'] == 'img') { $water_id = intval($this->input['water_id']); if (!intval($water_id)) { $water_id = $this->get_water_id(urldecode($this->input['app_bundle']), urldecode($this->input['module_bundle']), urldecode($this->input['catid'])); } if ($water_id == -1) { $water_id = 0; } $info['water_id'] = $water_id; } if (!hg_mkdir($path)) { return false; } else { if (!move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path . $info['filename'])) { return false; } else { $imginfo = getimagesize($path . $info['filename']); if ($this->input['trans_format'] && $this->input['trans_format'] != $info['type']) { $tmp_img = ''; switch ($imginfo[2]) { case 1: //gif $tmp_img = imagecreatefromgif($path . $info['filename']); break; case 2: //jpg $tmp_img = imagecreatefromjpeg($path . $info['filename']); break; case 3: //png $tmp_img = imagecreatefrompng($path . $info['filename']); break; default: break; } if ($tmp_img) { switch ($this->input['trans_format']) { case 'png': $info['type'] = 'png'; imagepng($tmp_img, $path . $tmp_filename . '.' . $info['type']); break; case 'jpg': $info['type'] = 'jpg'; imagejpeg($tmp_img, $path . $tmp_filename . '.' . $info['type']); break; case 'gif': $info['type'] = 'gif'; imagegif($tmp_img, $path . $tmp_filename . '.' . $info['type']); break; default: $info['type'] = 'png'; imagepng($tmp_img, $path . $tmp_filename . '.' . $info['type']); break; } @unlink($path . $info['filename']); $info['filename'] = $tmp_filename . '.' . $info['type']; imagedestroy($tmp_img); } } $info['imgwidth'] = $imginfo[0]; $info['imgheight'] = $imginfo[1]; $info['filesize'] = $_FILES["Filedata"]["size"]; $info['create_time'] = TIMENOW; $info['ip'] = hg_getip(); $info['nums'] = 1; $info['bs'] = hg_getimg_bs(); $info['id'] = $this->insert_data($info); //如果有水印则创建json文件记录水印信息,并记录水印关系表 if (!empty($info['water_id'])) { $this->createFile($info['water_id'], $info['bundle_id'], $info['filepath'], $info['filename'], hg_getimg_bs()); } $imgurl = hg_getimg_host(); $info['url'] = hg_material_link($imgurl, app_to_dir($info['bundle_id'], $type), $info['filepath'], $info['filename']); //unset 防止返回错误 $info['host'] = $imgurl; $info['dir'] = app_to_dir($info['bundle_id'], $info['mark']); $info['code'] = str_replace(array('{filename}', '{name}'), array($info['url'], $info['name']), $gMaterialTpye[$info['mark']][$info['type']]['code']); unset($info["bs"], $info['user_id'], $info['user_name'], $info['client_id'], $info['client_name'], $info['water_id'], $info['catid'], $info['nums']); return $info; } } } } }
function hg_getimg_host($bs = "") { global $gGlobalConfig; if (!$bs) { $bs = hg_getimg_bs(); } $host = $gGlobalConfig["imgurls"][$bs]; if ($host) { return $host; } return IMG_URL; }