Discuz!官方免费开源建站系统

 找回密码
 立即注册
搜索

[发布] 分类信息模型中的图片(image) 字段采用上传方式

[复制链接]
绝代疯子 发表于 2008-8-26 23:17:31 | 显示全部楼层 |阅读模式
额...功能就是 DZ的分类模型里的图片类型的分类信息,让其采用上传方式...
效果: test.jpg
1.jpg
2.jpg
步骤如下:
首先打开模板: 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 编辑 ]

新建_文本文档.rar

2.86 KB, 下载次数: 364

安装步骤

回复

使用道具 举报

e_zailai 发表于 2008-8-26 23:39:05 | 显示全部楼层
具体是什么东西呢???有没有演示
回复

使用道具 举报

 楼主| 绝代疯子 发表于 2008-8-27 00:22:59 | 显示全部楼层
不好意思..
没有演示站点。。。
回复

使用道具 举报

churujianghu 发表于 2008-8-27 09:45:09 | 显示全部楼层
好东东!这个6.0可以用不!?
回复

使用道具 举报

 楼主| 绝代疯子 发表于 2008-8-27 09:50:11 | 显示全部楼层
(::24::)
没试过.....
回复

使用道具 举报

tyiser 发表于 2008-8-27 09:54:14 | 显示全部楼层
很不错! 谢谢楼主~~~
回复

使用道具 举报

pdfsb 发表于 2008-11-26 00:07:22 | 显示全部楼层
十分受用,因本地测试,等我弄好我的站再贴个显示吧!
回复

使用道具 举报

灰空间2 发表于 2008-12-18 20:02:46 | 显示全部楼层
很好,尝试中。如果成功的话再给大家发个演示站。
回复

使用道具 举报

灰空间2 发表于 2008-12-18 20:42:02 | 显示全部楼层
演示地址在这里:大家看看吧:http://www.050910.cn/post.php?ac ... e%3D1&typeid=12

截图: 未命名.jpg
未命名2.jpg
回复

使用道具 举报

holmes593 发表于 2009-1-3 22:29:51 | 显示全部楼层
7.0能用么?好功能!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2025-9-13 08:07 , Processed in 0.100701 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表