|
发表于 2024-1-16 14:03:46
|
查看全部
这个代码:
- <div class="mimg cl">
- <a href="javascript:;" class="post_imgbtn"><i class="dm-image"></i>{lang e_img_attach}<input type="file" name="Filedata" id="filedata" multiple="multiple" accept=".jpg,.jpeg,.gif,.png,.bmp,image/jpeg,image/gif,image/png,image/bmp" /></a>
- <a href="javascript:;" class="post_attbtn"><i class="dm-star-fill"></i>{lang upload_attach}<input type="file" name="Filedata" id="attfiledata" /></a>
- </div>
复制代码
就是</div>的下边在添加
- <script type="text/javascript" src="{STATICURL}js/mobile/ajaxfileupload.js?{VERHASH}"></script>
- <script type="text/javascript" src="{STATICURL}js/mobile/buildfileupload.js?{VERHASH}"></script>
- <script type="text/javascript">
- var imgexts = typeof imgexts == 'undefined' ? 'jpg, jpeg, gif, png' : imgexts;
- var STATUSMSG = {
- '-1' : '{lang uploadstatusmsgnag1}',
- '0' : '{lang uploadstatusmsg0}',
- '1' : '{lang uploadstatusmsg1}',
- '2' : '{lang uploadstatusmsg2}',
- '3' : '{lang uploadstatusmsg3}',
- '4' : '{lang uploadstatusmsg4}',
- '5' : '{lang uploadstatusmsg5}',
- '6' : '{lang uploadstatusmsg6}',
- '7' : '{lang uploadstatusmsg7}(' + imgexts + ')',
- '8' : '{lang uploadstatusmsg8}',
- '9' : '{lang uploadstatusmsg9}',
- '10' : '{lang uploadstatusmsg10}',
- '11' : '{lang uploadstatusmsg11}',
- '12' : '{lang uploadstatusmsg12}',
- '13' : '{lang uploadstatusmsg13}'
- };
- var form = $('#postform');
- $(document).on('change', '#filedata', function() {
- popup.open('<img src="' + IMGDIR + '/imageloading.gif">');
- uploadsuccess = function(data) {
- if(data == '') {
- popup.open('{lang uploadpicfailed}', 'alert');
- }
- var dataarr = data.split('|');
- if(dataarr[0] == 'DISCUZUPLOAD' && dataarr[2] == 0) {
- popup.close();
- $('#imglist').append('<li><div><span aid="'+dataarr[3]+'" class="del"><a href="javascript:;"><i class="dm-error"></i></a></span><span class="p_img"><a href="javascript:;" onclick="addsmilies(\'[attachimg]'+dataarr[3]+'[/attachimg]\')"><img style="height:54px;width:54px;" id="aimg_'+dataarr[3]+'" src="{$_G['setting']['attachurl']}forum/'+dataarr[5]+'" /></a></span><input type="hidden" name="attachnew['+dataarr[3]+'][description]" /><div></li>');
- } else {
- var sizelimit = '';
- if(dataarr[7] == 'ban') {
- sizelimit = '{lang uploadpicatttypeban}';
- } else if(dataarr[7] == 'perday') {
- sizelimit = '{lang donotcross}'+Math.ceil(dataarr[8]/1024)+'K)';
- } else if(dataarr[7] > 0) {
- sizelimit = '{lang donotcross}'+Math.ceil(dataarr[7]/1024)+'K)';
- }
- popup.open(STATUSMSG[dataarr[2]] + sizelimit, 'alert');
- }
- };
- if(typeof FileReader != 'undefined' && this.files[0]) {//note 支持html5上传新特性
- for (const file of this.files) {
- var tmpfiles = [];
- tmpfiles[0] = file;
- $.buildfileupload({
- uploadurl:'misc.php?mod=swfupload&operation=upload&type=image&inajax=yes&infloat=yes&simple=2',
- files:tmpfiles,
- uploadformdata:{uid:"$_G['uid']", hash:"<!--{eval echo md5(substr(md5($_G['config']['security']['authkey']), 8).$_G['uid'])}-->"},
- uploadinputname:'Filedata',
- maxfilesize:"$swfconfig['max']",
- success:uploadsuccess,
- error:function() {
- popup.open('{lang uploadpicfailed}', 'alert');
- }
- });
- }
- } else {
- $.ajaxfileupload({
- url:'misc.php?mod=swfupload&operation=upload&type=image&inajax=yes&infloat=yes&simple=2',
- data:{uid:"$_G['uid']", hash:"<!--{eval echo md5(substr(md5($_G['config']['security']['authkey']), 8).$_G['uid'])}-->"},
- dataType:'text',
- fileElementId:'filedata',
- success:uploadsuccess,
- error: function() {
- popup.open('{lang uploadpicfailed}', 'alert');
- }
- });
- }
- });
- $(document).on('change', '#attfiledata', function() {
- popup.open('<img src="' + IMGDIR + '/imageloading.gif">');
- uploadsuccess = function(data) {
- if(data == '') {
- popup.open('{lang uploadpicfailed}', 'alert');
- }
- var dataarr = data.split('|');
- if(dataarr[0] == 'DISCUZUPLOAD' && dataarr[2] == 0) {
- popup.close();
- var video_file = '';
- var file_ex = 'unknown.gif';
- if (/bittorrent$|torrent$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'torrent.gif';
- } else if (/pdf$|pdf$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'pdf.gif';
- } else if (/(jpg|gif|png|bmp)$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'image.gif';
- } else if (/(swf|fla|flv|swi)$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'flash.gif';
- } else if (/(wav|mid|mp3|m3u|wma|asf|asx|vqf|mpg|mpeg|avi|wmv|mp4|ogv|webm|ogg)$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'av.gif';
- } else if (/(ra|rm|rv)$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'real.gif';
- } else if (/(php|js|pl|cgi|asp|htm|html|xml)$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'html.gif';
- } else if (/(txt|rtf|wri|chm)$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'text.gif';
- } else if (/(doc|ppt)$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'msoffice.gif';
- } else if (/rar$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'rar.gif';
- } else if (/(zip|arj|arc|cab|lzh|lha|tar|gz)$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'zip.gif';
- } else if (/(exe|com|bat|dll)$/.test(dataarr[6].toLowerCase())) {
- file_ex = 'binary.gif';
- } else {
- file_ex = 'unknown.gif';
- }
- <!--{if $_G['setting']['allowattachurl']}-->
- if (/mp3$/.test(dataarr[6].toLowerCase())) {
- video_file = '<span class="btn" onclick="addsmilies(\'[audio]attach://' + dataarr[3] + '.mp3[/audio]\')">{lang forum_post_insert}{lang e_audio}</span>';
- } else if (/(mp4)$/.test(dataarr[6].toLowerCase())) {
- video_file = '<span class="btn" onclick="addsmilies(\'[media=x,500,375]attach://' + dataarr[3] + '.mp4[/media]\')">{lang forum_post_insert}{lang e_video}</span>';
- }
- <!--{/if}-->
- $('#attlist').append('<li class="b_t"><div class="tit"><span aid="'+dataarr[3]+'" up="1" class="del btn f_f"><a href="javascript:;"><i class="dm-trash z"></i></a></span>'+video_file+'<span class="btn" onclick="addsmilies(\'[attach]'+dataarr[3]+'[/attach]\')">{lang forum_post_insert}</span><img src="static/image/filetype/'+file_ex+'" border="0" class="vm mimg" alt=""><span class="link">'+dataarr[6]+'</span></div><!--{if $_GET['result'] != 'simple'}--><div class="minput"><div class="attms flex-box"><span class="f_c">{lang description}</span><input type="text" name="attachnew['+dataarr[3]+'][description]" value="" class="input flex"></div></div><div class="minput"><!--{if $_G['group']['allowsetattachperm']}--><!--{if $_G['cache']['groupreadaccess']}--><div class="attqx flex-box"><span>{lang forum_post_perm}</span><div class="flex"><select name="attachnew['+dataarr[3]+'][readperm]" id="readperm'+dataarr[3]+'" class="sort_sel"><option value="" selected="selected">{lang unlimited}</option><!--{loop $_G['cache']['groupreadaccess'] $val}--><option value="$val['readaccess']">$val['grouptitle']({lang readperm}: $val['readaccess'])</option><!--{/loop}--><option value="255"{if $temp['readperm'] == 255} selected{/if}>{lang highest_right}</option></select></div></div><!--{/if}--><!--{/if}--><!--{if $_G['group']['maxprice']}--><div class="attjg flex-box"><span>{lang price}</span><input type="text" name="attachnew['+dataarr[3]+'][price]" value="0" class="input price flex"><em>{$_G['setting']['extcredits'][$_G['setting']['creditstransextra'][1]][title]}</em></div><!--{/if}--></div><!--{/if}--></li>');
- } else {
- var sizelimit = '';
- if(dataarr[7] == 'ban') {
- sizelimit = '{lang uploadpicatttypeban}';
- } else if(dataarr[7] == 'perday') {
- sizelimit = '{lang donotcross}'+Math.ceil(dataarr[8]/1024)+'K)';
- } else if(dataarr[7] > 0) {
- sizelimit = '{lang donotcross}'+Math.ceil(dataarr[7]/1024)+'K)';
- }
- popup.open(STATUSMSG[dataarr[2]] + sizelimit, 'alert');
- }
- };
- if(typeof FileReader != 'undefined' && this.files[0]) {//note 支持html5上传新特性
- for (const file of this.files) {
- var tmpfiles = [];
- tmpfiles[0] = file;
- $.buildfileupload({
- uploadurl:'misc.php?mod=swfupload&operation=upload&fid={$_G['fid']}&inajax=yes&infloat=yes&simple=2',
- files:tmpfiles,
- uploadformdata:{uid:"$_G['uid']", hash:"<!--{eval echo md5(substr(md5($_G['config']['security']['authkey']), 8).$_G['uid'])}-->"},
- uploadinputname:'Filedata',
- maxfilesize:"$swfconfig['max']",
- success:uploadsuccess,
- error:function() {
- popup.open('{lang uploadpicfailed}', 'alert');
- }
- });
- }
- } else {
- $.ajaxfileupload({
- url:'misc.php?mod=swfupload&operation=upload&fid={$_G['fid']}&inajax=yes&infloat=yes&simple=2',
- data:{uid:"$_G['uid']", hash:"<!--{eval echo md5(substr(md5($_G['config']['security']['authkey']), 8).$_G['uid'])}-->"},
- dataType:'text',
- fileElementId:'attfiledata',
- success:uploadsuccess,
- error: function() {
- popup.open('{lang uploadpicfailed}', 'alert');
- }
- });
- }
- });
- $('#postsubmit').on('click', function() {
- var obj = $(this);
- if(obj.attr('disable') == 'true') {
- return false;
- }
- obj.attr('disable', 'true').removeClass('btn_pn_blue').addClass('btn_pn_grey');
- popup.open('<img src="' + IMGDIR + '/imageloading.gif">');
- var postlocation = '';
- if(typeof geo !== 'undefined' && geo.errmsg === '' && geo.loc) {
- postlocation = geo.longitude + '|' + geo.latitude + '|' + geo.loc;
- }
- var myform = document.getElementById('postform');
- var formdata = new FormData(myform);
- $.ajax({
- type:'POST',
- url:form.attr('action') + '&geoloc=' + postlocation + '&handlekey='+form.attr('id')+'&inajax=1',
- data:formdata,
- cache:false,
- contentType:false,
- processData:false,
- dataType:'xml'
- })
- .success(function(s) {
- popup.open(s.lastChild.firstChild.nodeValue);
- })
- .error(function() {
- popup.open('{lang networkerror}', 'alert');
- });
- return false;
- });
- $(document).on('click', '.del', function() {
- var obj = $(this);
- $.ajax({
- type:'GET',
- url:'forum.php?mod=ajax&action=deleteattach&inajax=yes&aids[]=' + obj.attr('aid') + (obj.attr('up') == 1 ? '&tid={$postinfo['tid']}&pid={$postinfo['pid']}&formhash={FORMHASH}' : ''),
- })
- .success(function(s) {
- obj.closest('li').remove();
- })
- .error(function() {
- popup.open('{lang networkerror}', 'alert');
- });
- return false;
- });
- </script>
复制代码
试试看行不行? |
|