所有的鸟儿他们都知道, 他们的巢应该筑在什么地方, 鸟儿知道自己该在什么地方筑巢, 那就意味着他们了解他们自己的使命。 我们身为万物之灵的人类, 怎么会不知道,连鸟儿都知道的道理呢?
简单仿discuz上传附件定位。
简单仿discuz上传附件定位。

简单仿discuz上传附件定位。

完全仿的discuz。  上传附件的时候排版于内容之中。
实现正文,附件混编 。<?php
if ($_FILES[attach]) {
    echo "<pre>";
    print_r($_POST);
    print_r($_FILES);
    exit();
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>发表新主题:<hr />
<form enctype="multipart/form-data" action="" method="POST">

<p>标题:<input type="text" name="note_title"></p>
<p>内容:<textarea id="note_main" name="note_main" cols="40" rows="4"></textarea>
</p>
<p>上传图片:
<br />
<hr />
<div id="attachDiv"  style="display:none" >
            <div id="functions">
                        <input type="file" name="attach[]" />
                        <span id="localfile[]"></span>
                        <input type="hidden" name="localid[]" />
            </div>
            
            
</div>
<hr />
<div id="attachDivBody">  
</div>
<hr />
</p>
<p>上传视频:<input type="text" name="vadio"></p>
<p>是否悬赏:<input name="note_type_xuanshang" type="radio" value="1"> 是   <input name="note_type_xuanshang" type="radio" value="0"> 否 悬赏分数:<input name="note_xuanshang_score" type="radio" value="1">1分 <input name="note_xuanshang_score" type="radio" value="2">2分 <input name="note_xuanshang_score" type="radio" value="5">5分 <input name="note_xuanshang_score" type="radio" value="10">10分 <input name="note_xuanshang_score" type="radio" value="20">20分 </p>
<p>是否使用喊话道具:<input name="note_type_hanhua" type="radio" value="1"> 是 <input name="note_type_hanhua" type="radio" value="0"> 否 </p>
<p><input type="submit" value="提交"></p>
</form>
<script type="text/javascript">
function $(id){
    return document.getElementById(id);
}
var aid = 1;
var attachexts = new Array();
var attachwh = new Array();
function addAttach() {
    newnode = $(‘functions’).cloneNode(true);
    var id = aid;
    var tags;
    newnode.id = ‘functions’ + id;
    tags = newnode.getElementsByTagName(‘input’);
    for(i in tags) {
        if(tags[i].name == ‘attach[]’) {
            tags[i].id = ‘attach_’ + id;
            tags[i].onchange = function() {insertAttach(id)};
            tags[i].unselectable = ‘on’;
            tags[i].value = "";
        }
        if(tags[i].name == ‘localid[]’) {
            tags[i].value = id;
        }
    }
    tags = newnode.getElementsByTagName(‘span’);
    for(i in tags) {
        if(tags[i].id == ‘localfile[]’) {
            tags[i].id = ‘localfile_’ + id;
        }
    }
    aid++;
    $(‘attachDivBody’).appendChild(newnode);
}

addAttach();

function insertAttach(id){
    var path = $(‘attach_’ + id).value;
    var ext = path.lastIndexOf(‘.’) == -1 ? ” : path.substr(path.lastIndexOf(‘.’) + 1, path.length).toLowerCase();
    var re = new RegExp("(^|\\s|,)" + ext + "($|\\s|,)", "ig");
    var localfile = $(‘attach_’ + id).value.substr($(‘attach_’ + id).value.replace(/\\/g, ‘/’).lastIndexOf(‘/’) + 1);
//    attachexts[id] = is_ie && in_array(ext, [‘gif’, ‘jpg’, ‘png’, ‘bmp’]) && typeof supe == ‘undefined’ ? 2 : 1;
    attachexts[id] = false && in_array(ext, [‘gif’, ‘jpg’, ‘png’, ‘bmp’]) && typeof supe == ‘undefined’ ? 2 : 1;
    if(path == ”) {
        return;
    }
    
    $(‘localfile_’ + id).innerHTML = ‘<a href="###delAttach" onclick="delAttach(‘ + id + ‘)">[删除]</a> <a href="###insertAttach" title="插入" onclick="insertAttachtext(‘ + id + ‘);return false;">[插入]</a> ‘+
    (attachexts[id] == 2 ? ‘<span id="localimgpreview_’ + id + ‘" onmouseover="showMenu(this.id, 0, 0, 1, 0)"> <span class="smalltxt">[‘ +id + ‘]</span> <a href="###attachment" onclick="insertAttachtext(‘ + id + ‘);return false;">’ + localfile + ‘</a></span>’ : ‘<span class="smalltxt">[‘ + id + ‘]</span> ‘ + localfile);
    $(‘attach_’ + id).style.display = ‘none’;
    addAttach();
}

function delAttach(id){
    $(‘attachDivBody’).removeChild($(‘attach_’ + id).parentNode);
    //$(‘attachDivBody’).innerHTML == ” && addAttach();
    //$(‘localimgpreview_’ + id + ‘_menu’) ? document.body.removeChild($(‘localimgpreview_’ + id + ‘_menu’)) : null;
}

function insertAttachtext(id){
    insertText(‘[local]’ + id + ‘[/local]’, false)
}
function insertText(text, movestart, moveend, select, sel) {
       
    $("note_main").focus();
    editdoc = $("note_main");
     if(document.selection && document.selection.createRange) {
            sel = document.selection.createRange();
            sel.text = text.replace(/\r?\n/g, ‘\r\n’);
            if(movestart) {
                sel.moveStart(‘character’, -strlen(text) +movestart);
                sel.moveEnd(‘character’, -moveend);
            } else if(movestart !== false) {
                sel.moveStart(‘character’, -strlen(text));
            }
            sel.select();
        } else {
                     editdoc.value += text;
        }
}
 
</script>
</body>
</html>

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注