⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 post.func.php

📁 极限网络智能办公系统 Office Automation V3.0官方100%源代码.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php

/*
	[Discuz!] (C)2001-2007 Comsenz Inc.
	This is NOT a freeware, use is subject to license terms

	$RCSfile: post.func.php,v $
	$Revision: 1.60.2.8 $
	$Date: 2007/03/21 15:52:38 $
*/

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

function attach_upload($varname = 'attach') {
	global $db, $tablepre, $extension, $typemaxsize, $allowsetattachperm, $attachperm, $maxprice, $attachprice, $attachdesc, $attachsave, $attachdir, $thumbstatus, $thumbwidth, $thumbheight,
		$maxattachsize, $maxsizeperday, $attachextensions, $watermarkstatus, $watermarktype, $watermarktrans, $watermarkquality, $_FILES, $discuz_uid;

	//watermark filename
	$watermark_file = $watermarktype ? './images/common/watermark.png' : './images/common/watermark.gif';
	$watermarkstatus = $GLOBALS['forum']['disablewatermark'] ? 0 : $watermarkstatus;

	$attachments = $attacharray = array();

	if(isset($_FILES[$varname]) && is_array($_FILES[$varname])) {
		foreach($_FILES[$varname] as $key => $var) {
			foreach($var as $id => $val) {
				$attachments[$id][$key] = $val;
			}
		}
	}

	if(empty($attachments)) {
		return FALSE;
	}

	foreach($attachments as $key => $attach) {

		$attach_saved = false;

		$attach['uid'] = $discuz_uid;
		if(!disuploadedfile($attach['tmp_name']) || !($attach['tmp_name'] != 'none' && $attach['tmp_name'] && $attach['name'])) {
			continue;
		}

		$filename = daddslashes($attach['name']);

		$attach['ext'] = $extension = strtolower(fileext($attach['name']));

		if(substr($attach['type'], 0, 5) == 'image') {
			$attach['isimage'] = 1;
		} else {
			$attach['isimage'] = 0;
		}
		$attach['thumb'] = 0;

		$attach['name'] = htmlspecialchars($attach['name'], ENT_QUOTES);
		if(strlen($attach['name']) > 90) {
			$attach['name'] = 'abbr_'.md5($attach['name']).'.'.$extension;
		}

		if($attachextensions && (!preg_match("/(^|\s|,)".preg_quote($attach['ext'], '/')."($|\s|,)/i", $attachextensions) || !$attach['ext'])) {
			upload_error('post_attachment_ext_notallowed', $attacharray);
		}

		if(empty($attach['size'])) {
			upload_error('post_attachment_size_invalid', $attacharray);
		}

		if($maxattachsize && $attach['size'] > $maxattachsize) {
			upload_error('post_attachment_toobig', $attacharray);
		}

		$query = $db->query("SELECT maxsize FROM {$tablepre}attachtypes WHERE extension='".addslashes($attach['ext'])."'");
		if($type = $db->fetch_array($query)) {
			if($type['maxsize'] == 0) {
				upload_error('post_attachment_ext_notallowed', $attacharray);
			} elseif($attach['size'] > $type['maxsize']) {
				require_once DISCUZ_ROOT.'./include/attachment.func.php';
				$typemaxsize = sizecount($type['maxsize']);
				upload_error('post_attachment_type_toobig', $attacharray);
			}
		}

		if($attach['size'] && $maxsizeperday) {
			if(!isset($todaysize)) {
				$query = $db->query("SELECT SUM(a.filesize) FROM {$tablepre}posts p
					LEFT JOIN {$tablepre}attachments a USING (pid)
					WHERE p.authorid='$GLOBALS[discuz_uid]' AND p.dateline>'$GLOBALS[timestamp]'-86400 AND p.attachment>'0'");
				$todaysize = intval($db->result($query, 0));
			}
			$todaysize += $attach['size'];
			if($todaysize >= $maxsizeperday) {
				upload_error('post_attachment_quota_exceed', $attacharray);
			}
		}

		if($attachsave) {
			switch($attachsave) {
				case 1: $attach_subdir = 'forumid_'.$GLOBALS['fid']; break;
				case 2: $attach_subdir = 'ext_'.$extension; break;
				case 3: $attach_subdir = 'month_'.date('ym'); break;
				case 4: $attach_subdir = 'day_'.date('ymd'); break;
			}
			$attach_dir = $attachdir.'/'.$attach_subdir;
			if(!is_dir($attach_dir)) {
				mkdir($attach_dir, 0777);
				fclose(fopen($attach_dir.'/index.htm', 'w'));
			}
			$attach['attachment'] = $attach_subdir.'/';
		} else {
			$attach['attachment'] = '';
		}

		$attach['attachment'] .= preg_replace("/(php|phtml|php3|php4|jsp|exe|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i", "_\\1\\2",
			date('Ymd').'_'.substr(md5($filename.microtime()), 12).random(12).'.'.$extension);

		$target = $attachdir.'/'.stripslashes($attach['attachment']);

		if(@copy($attach['tmp_name'], $target) || (function_exists('move_uploaded_file') && @move_uploaded_file($attach['tmp_name'], $target))) {
			@unlink($attach['tmp_name']);
			$attach_saved = true;
		}

		if(!$attach_saved && @is_readable($attach['tmp_name'])) {
			@$fp = fopen($attach['tmp_name'], 'rb');
			@flock($fp, 2);
			@$attachedfile = fread($fp, $attach['size']);
			@fclose($fp);

			@$fp = fopen($target, 'wb');
			@flock($fp, 2);
			if(@fwrite($fp, $attachedfile)) {
				@unlink($attach['tmp_name']);
				$attach_saved = true;
			}
			@fclose($fp);

		}

		if($attach_saved) {
			@chmod($target, 0644);
			if(in_array($attach['ext'], array('jpg', 'jpeg', 'gif', 'png', 'swf', 'bmp')) && function_exists('getimagesize') && !@getimagesize($target)) {
				@unlink($target);
				upload_error('post_attachment_ext_notallowed', $attacharray);
			} else {
				$attachinfo = @getimagesize($target);
				if(in_array($attachinfo['mime'], array('image/jpeg', 'image/gif', 'image/png'))) {

					if($thumbstatus) {
						$img_w		= $attachinfo[0];
						$img_h		= $attachinfo[1];

						$animatedgif = 0;
						if($attachinfo['mime'] == 'image/gif') {
							if(empty($attachedfile)) {
								$fp = fopen($target, 'rb');
								$attachedfile = fread($fp, $attach['size']);
								fclose($fp);
							}
							$animatedgif = strpos($attachedfile, 'NETSCAPE2.0') === FALSE ? 0 : 1;
						}

						if(!$animatedgif && ($img_w >= $thumbwidth || $img_h >= $thumbheight)) {
							switch($attachinfo['mime']) {
								case 'image/jpeg':
									$attach_photo = imageCreateFromJPEG($target);
									break;
								case 'image/gif':
									$attach_photo = imageCreateFromGIF($target);
									break;
								case 'image/png':
									$attach_photo = imageCreateFromPNG($target);
									break;
							}

							$x_ratio = $thumbwidth / $img_w;
							$y_ratio = $thumbheight / $img_h;

							if(($x_ratio * $img_h) < $thumbheight) {
								$thumb['height'] = ceil($x_ratio * $img_h);
								$thumb['width'] = $thumbwidth;
							} else {
								$thumb['width'] = ceil($y_ratio * $img_w);
								$thumb['height'] = $thumbheight;
							}

							$thumb_photo = imagecreatetruecolor($thumb['width'], $thumb['height']);
							imageCopyreSampled($thumb_photo, $attach_photo ,0, 0, 0, 0, $thumb['width'], $thumb['height'], $img_w, $img_h);
							imageJPEG($thumb_photo, $target.'.thumb.jpg');
							$attach['thumb'] = 1;
						}
					}
					if($watermarkstatus) {
						$watermarkinfo	= @getimagesize($watermark_file);
						$watermark_logo = $watermarktype ? imageCreateFromPNG($watermark_file) : imageCreateFromGIF($watermark_file);
						$logo_w		= $watermarkinfo[0];
						$logo_h		= $watermarkinfo[1];
						$img_w		= $attachinfo[0];
						$img_h		= $attachinfo[1];
						$wmwidth	= $img_w - $logo_w;
						$wmheight	= $img_h - $logo_h;

						$animatedgif = 0;
						if($attachinfo['mime'] == 'image/gif') {
							if(empty($attachedfile)) {
								$fp = fopen($target, 'rb');
								$attachedfile = fread($fp, $attach['size']);
								fclose($fp);
							}
							$animatedgif = strpos($attachedfile, 'NETSCAPE2.0') === FALSE ? 0 : 1;
						}

						if(is_readable($watermark_file) && $wmwidth > 10 && $wmheight > 10 && !$animatedgif) {
							switch($attachinfo['mime']) {
								case 'image/jpeg':
									$dst_photo = imageCreateFromJPEG($target);
									break;
								case 'image/gif':
									$dst_photo = imageCreateFromGIF($target);
									break;
								case 'image/png':
									$dst_photo = imageCreateFromPNG($target);
									break;
							}

							switch($watermarkstatus) {
								case 1:
									$x = +5;
									$y = +5;
									break;
								case 2:
									$x = ($img_w - $logo_w) / 2;
									$y = +5;
									break;
								case 3:
									$x = $img_w - $logo_w - 5;
									$y = +5;
									break;
								case 4:
									$x = +5;
									$y = ($img_h - $logo_h) / 2;
									break;
								case 5:
									$x = ($img_w - $logo_w) / 2;
									$y = ($img_h - $logo_h) / 2;
									break;
								case 6:
									$x = $img_w - $logo_w;
									$y = ($img_h - $logo_h) / 2;
									break;
								case 7:
									$x = +5;
									$y = $img_h - $logo_h - 5;
									break;
								case 8:
									$x = ($img_w - $logo_w) / 2;
									$y = $img_h - $logo_h - 5;
									break;
								case 9:
									$x = $img_w - $logo_w - 5;
									$y = $img_h - $logo_h - 5;
									break;
							}

							if($watermarktype) {
								imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);
							} else {
								imageAlphaBlending($watermark_logo, true);
								imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
							}

							switch($attachinfo['mime']) {
								case 'image/jpeg':

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -