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

📄 upload.inc.php

📁 uch争车位,适合大家的使用 可以实验
💻 PHP
字号:
<?php
if(!defined('IN_DISCUZ')) {
	exit('Access Deined');
}

//设定$maxattachsize和图片文件保存路径$attachdir
//缩略图的宽度$thumbwidth和高度$thumbheight
$thumbwidth = 180;
$thumbheight = 180;


$filename = daddslashes($attach['name']);
$attach['ext'] = $extension = strtolower(fileext($attach['name']));
$attach['name'] = dhtmlspecialchars($attach['name']);
$attach['thumb'] = 0;

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

if(empty($attach['size'])) {
	showmessage('post_attachment_size_invalid');
}

/*
if($maxattachsize && $attach['size'] > $maxattachsize) {
	showmessage('post_attachment_toobig');
}
*/
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;
		case 5: $attach_subdir = 'blcar'; 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.'/'.$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')) && function_exists('getimagesize') && !@getimagesize($target)) {
		@unlink($target);
		showmessage('post_attachment_ext_notallowed');
	} else {
		require_once DISCUZ_ROOT.'./include/image.class.php';

		$image = new Image($attachedfile, $target, $attach);
		if($image->imagecreatefromfunc && $image->imagefunc) {

			$image->Thumb($thumbwidth, $thumbheight);
			$image->Watermark();
			$attach = $image->attach;
		}
	}
}
else {
	showmessage('post_attachment_save_error');
}
?>

⌨️ 快捷键说明

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