额...功能就是 DZ的分类模型里的图片类型的分类信息,让其采用上传方式...
效果:
步骤如下:
首先打开模板: post_typeoption.htm
查找
<!--{if $option['type'] == 'calendar'}-->
在<!--{else}--!>前面添加:
<!--{elseif $option['type'] == 'image'}-->
<input type="file" name="tradeattach[]" class="absmiddle" size="45" id="typeoption[{$option[identifier]}]" onchange="attachpreview(this,
'tradeattach_preview', 80, 80)" tabindex="53" onBlur="check{$option[identifier]}()" value="$option[value]" $option[unchangeable]/>
<span id="tradeattach_preview">
<!--{if $tradeattach[attachment]}-->
<a href="$tradeattach[url]/$tradeattach[attachment]" target="_blank">
<!--{if $tradeattach['thumb']}-->
<img height="80" src="$tradeattach[url]/$tradeattach[attachment].thumb.jpg" border="0" alt="" />
<!--{else}-->
<img height="80" src="$tradeattach[url]/$tradeattach[attachment]" border="0" alt="" />
<!--{/if}-->
</a>
<!--{/if}-->
</span><!--{if $tradeattach[attachment]}--><input name="tradeaid" type="hidden" value="$tradeattach[aid]"><!--{/if}-->
<div id="tradeattach_preview_hidden" style="position: absolute; top: -100000px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader
(sizingMethod='image'); width: 80px; height: 80px"></div>ps:不改动时不要填写
然后打开include目录下的post.func.php
在if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
后面添加
function imagemodel_upload($varname = 'imageup') {
global $db, $tablepre, $extension, $typemaxsize, $allowsetattachperm, $attachperm, $maxprice, $attachprice, $attachdesc,
$attachsave, $attachdir, $thumbstatus, $thumbwidth, $thumbheight,
$maxattachsize, $maxsizeperday, $attachextensions, $watermarkstatus, $watermarktype, $watermarktrans,
$watermarkquality, $watermarktext, $_FILES, $discuz_uid;
$attachments = $attacharray = array();
static $safeext = array('jpg', 'jpeg', 'gif', 'png', 'swf', 'bmp', 'txt', 'zip', 'rar', 'doc', 'mp3');
static $imgext = array('jpg', 'jpeg', 'gif', 'png', 'bmp');
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'] = strtolower(fileext($attach['name']));
$extension = in_array($attach['ext'], $safeext) ? $attach['ext'] : 'attach';
if(in_array($attach['ext'], $imgext)) {
$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']).'.'.$attach['ext'];
}
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);
}
if($type = $db->fetch_first("SELECT maxsize FROM {$tablepre}attachtypes WHERE extension='".addslashes($attach
['ext'])."'")) {
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)) {
$todaysize = intval($db->result_first("SELECT SUM(filesize) FROM {$tablepre}attachments
WHERE uid='$GLOBALS[discuz_uid]' AND dateline>'$GLOBALS[timestamp]'-86400"));
}
$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.'/'.$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 {
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;
}
$attach['remote'] = ftpupload($target, $attach);
$attach['perm'] = $allowsetattachperm ? intval($attachperm[$key]) : 0;
$attach['description'] = cutstr(dhtmlspecialchars($attachdesc[$key]), 100);
$attach['price'] = $maxprice ? (intval($attachprice[$key]) <= $maxprice ? intval($attachprice[$key]) :
$maxprice) : 0;
$attacharray[$key] = $attach;
}
}
}
return !empty($attacharray) ? $attacharray : false;
}
然后查找: if($checkoption[$var]['required'] && !$typeoption[$var]) {
showmessage('threadtype_required_invalid', "post.php?action=$postaction&fid=$fid&typeid=$selecttypeid");
}
在后面添加:
elseif($checkoption[$var]['type'] == 'image')
{
if(!empty($_FILES['tradeattach']['tmp_name'][0])) {
$_FILES['imageup'] = array_merge_recursive((array)$_FILES['imageup'], $_FILES['tradeattach']);
}
if(is_array($_FILES['imageup'])) {
foreach($_FILES['imageup']['name'] as $imageupname) {
if($imageupname != '') {
checklowerlimit($postattachcredits);
break;
}
}
}
$attachment = ($attachments = imagemodel_upload()) ? 1 : 0;
if($attachments!=''){
foreach($attachments as $key => $imagemodel) {
$typeoption[$var]="attachments/".$imagemodel[attachment];}
}}
然后打开editpost.inc.php
查找$db->query("UPDATE {$tablepre}typeoptionvars SET value='$value' WHERE tid='$tid' AND optionid='$optionid'");
替换为:
if($value){$db->query("UPDATE {$tablepre}typeoptionvars SET value='$value' WHERE tid='$tid' AND optionid='$optionid'");}
基本上,就是这样了.
[ 本帖最后由 绝代疯子 于 2008-8-27 09:44 编辑 ] |
|