discuz中SWFUpload的调用和自定义

discuz中的SWFUpload使用的也就是知名的SWFUpload插件,不过好像做了一些自定义的功能。

在这我就直接说discuz中SWFUpload的使用:

显示文件PHP代码:

require_once libfile(‘function/upload’);
$swfconfig = getuploadconfig($_G['uid'], 0, false);

html代码:

<span id=”spanButtonPlaceholder”></span>
<script type=”text/javascript” src=”{$_G[setting][jspath]}upload.js?{VERHASH}”></script>
<script type=”text/javascript” >
var upload = new SWFUpload({
// Backend Settings
upload_url: “{$_G[siteurl]}train.php?mod=swfupload&ac=work”,//上传后台处理网址
post_params: {“uid” : “$_G[uid]“, “hash”:”$swfconfig[hash]“,”lid”:”$lid”},//传递参数

// File Upload Settings
file_size_limit : “$swfconfig[max]“,    // 100MB
file_types : “$swfconfig[imageexts][ext]“,
file_types_description : “$swfconfig[imageexts][depict]“,
file_upload_limit : 0,
file_queue_limit : 0,

// Event Handler Settings (all my handlers are in the Handler.js file)
swfupload_preload_handler : preLoad,
swfupload_load_failed_handler : loadFailed,
file_dialog_start_handler : fileDialogStart,
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : trainUploadSuccess,//上传成功后的处理函数
upload_complete_handler : uploadComplete,

// Button Settings
button_image_url : “{IMGDIR}/uploadbutton.png”,//该背景图片必须是一个sprite图片,从上到下包含了Flash按钮的正常、鼠标悬停、按下、禁用这四种状态。因此该图片的高度应该是Flash按钮高度的四倍
button_placeholder_id : “spanButtonPlaceholder”,
button_width: 134,
button_height: 42,
button_cursor:SWFUpload.CURSOR.HAND,
button_window_mode: “transparent”,

custom_settings : {
progressTarget : “imgUploadProgress”,
uploadSource: ‘train’,//自定义参数
uploadType: ‘work’,//自定义参数
imgBoxObj: $(‘imgattachlist’)
//thumbnail_height: 400,
//thumbnail_width: 400,
//thumbnail_quality: 100
},

// Debug Settings
debug: true
});
function trainUploadSuccess(file, serverData) {//单个文件处理函数,如果是多个请按照{$_G[setting][jspath]}upload.js的uploadSuccess进行编写
var data = eval(‘(‘+serverData+’)');
if(parseInt(data.wid)) {
showDialog(‘上传成功,将跳转作业页面’, ‘right’, ‘提示信息’, function(){window.location.href = ‘train.php?mod=work&wid=’+data.wid;}, 0, null, ”, ”, ”, ”, 3);
}else{
showDialog(‘上传失败,错误代码为:’+data.errorcode+’。请联系客服QQ:{$train_plugin[qq]}!’, ‘error’, ‘错误信息’);
}

}
</script>

php处理程序:

$_G['uid'] = intval($_POST['uid']);

if((empty($_G['uid']) && $_GET['ac'] != ‘upload’)  || $_POST['hash'] != md5(substr(md5($_G['config']['security']['authkey']), 8).$_G['uid'])) {
exit();
} else {

//处理上传的文件

$_FILES["Filedata"]['name'] = addslashes(diconv(urldecode($_FILES["Filedata"]['name']), ‘UTF-8′));//编码转换

//处理$_FILES["Filedata"]

echo “{\”picid\”:\”0\”, \”url\”:\”0\”, \”bigimg\”:\”0\”, \”errorcode\”:$errorcode}”;//输出内容,用于js处理调用

 

你可能感兴趣的:(swfupload)