📄 upload.jsp
字号:
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>图片上传</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/common/upload/SWFUpload/SWFUpload.js"></script>
<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #666666;
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
SCROLLBAR-FACE-COLOR: #EBEBEB; SCROLLBAR-HIGHLIGHT-COLOR: #EBEBEB; SCROLLBAR-SHADOW-COLOR: #C5C5C5; SCROLLBAR-3DLIGHT-COLOR: #C5C5C5; SCROLLBAR-ARROW-COLOR: #C5C5C5; SCROLLBAR-TRACK-COLOR: #EBEBEB; SCROLLBAR-DARKSHADOW-COLOR: #EBEBEB
}
.all {
height: 200px;
width: 420px;
}
.but_01 {
width: 420px;
padding-left: 30px;
}
.but_02 {
width: 420px;
padding-left: 30px;
}
.note {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #006600;
padding-left: 30px;
padding-top: 10px;
}
#bg_02 {
background-attachment: fixed;
background: url(/common/upload/SWFUpload/images/bg_02.gif);
background-repeat: no-repeat;
background-position: left top;
height: 200px;
width: 420px;
text-align: center;
}
#bg_02 .font_red {
font-size: 11px;
color: #CC0000;
}
#bg_02 .file {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #333333;
text-align: right;
padding-top: 30px;
padding-right: 10px;
}
#bg_02 .table {
background-color: #FFFFFF;
height: 100px;
width: 350px;
text-align: left;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
color: #65331D;
}
#box{
overflow:auto; height:180px; width:100%; font-size: 11px; color: #999999; font-style: normal;
}
span.progressBar {
width: 100px;
height: 2px;
display: block;
font-size: 10px;
float: left;
background: #f0f0f0 url(/common/upload/SWFUpload/images/progressbar.png) no-repeat -100px 0px;
}
.fileUploading { background: #fee727; }
#fileSize{
text-align: right;
margin-left: 5px;
}
#fileList{
width:98%;
background-color: #EBEBEB;
border: 0px;
}
#fileList td{
background-color: #FFFFFF;
}
#fileList .flag1{
width: 15px;
height: 15px;
background:#FFFFFF url(/common/upload/SWFUpload/images/select.jpg) no-repeat center center ;
}
#fileList .flag2{
width: 15px;
height: 15px;
background:#FFFFFF url(/common/upload/SWFUpload/images/selected.jpg) no-repeat center center ;
}
.progressTD{
width: 100px;
}
.delectBtn{
width: 30px;
text-align: center;
}
.button {
height: 20px;
border: 1px solid #FF9000;
font-size: 12px;
color: #333333;
line-height: 18px;
text-align: center;
padding-right: 5px;
padding-left: 5px;
}
</style>
<script type="text/javascript">
var swfu;
function initSwfu() {
// Max settings
swfu = new SWFUpload({
create_ui : true,
debug : false,
upload_script : "/upload.do?uploadKey=1111",
target : "SWFUploadTarget",
flash_path : "/common/upload/SWFUpload/SWFUpload.swf",
allowed_filesize : 102400, // 30 MB
allowed_filetypes : "*.jpg;*.gif;*.png;*.ico;*.jpeg",
allowed_filetypes_description : "所有图片文件",
browse_link_ID : "browse_link",
upload_link_ID : "upload_link",
flash_loaded_callback : 'swfu.flashLoaded',
//upload_file_queued_callback : "fileQueued",
upload_file_queued_callback : "fileQueuedByCustomize",
upload_file_start_callback : 'uploadFileStart',
upload_progress_callback : 'uploadProgress',
upload_file_complete_callback : 'uploadFileComplete',
upload_file_cancel_callback : 'uploadFileCancelled',
upload_queue_complete_callback : 'uploadQueueComplete',
upload_error_callback : 'uploadError',
upload_cancel_callback : 'uploadCancel',
auto_upload : false,
upload_file_error_callback:"whenerror"
});
//fix flash refresh;
swfu.loadFlash();
}
function GetCookieVal_(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie_(name, value)
//设定Cookie值
{
var expdate = new Date();
var argv = SetCookie_.arguments;
var argc = SetCookie_.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
function DelCookie_(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie_ (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function GetCookie_(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal_(j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function whenerror(errcode, file, msg) {
switch(errcode) {
case -10: // HTTP error
alert("Error Code: HTTP Error, File name: " + file.name + ", Message: " + msg);
break;
case -20: // No upload script specified
alert("Error Code: No upload script, File name: " + file.name + ", Message: " + msg);
break;
case -30: // IOError
alert("Error Code: IO Error, File name: " + file.name + ", Message: " + msg);
break;
case -40: // Security error
alert("Error Code: Security Error, File name: " + file.name + ", Message: " + msg);
break;
case -50: // Filesize too big
alert(file.name+"文件大小受限制, 文件大小: " + file.size +"K,不要超过"+swfu.settings['allowed_filesize']+'K');
break;
}
}
var isCancelAll = false;
/**
当有文件加入队列中是触发
**/
var totalSize=0;
function fileQueuedByCustomize(file, queuelength) {
totalSize+=file.size;
var listingfiles = document.getElementById("fileList");
var tr = listingfiles.insertRow();
tr.id=file.id;
var flag = tr.insertCell(); flag.className='flag2';
var fileName = tr.insertCell();
fileName.innerHTML=file.name;
var progressTD = tr.insertCell(); progressTD.className='progressTD';
progressTD.innerHTML='<span id="' + file.id +'progress" class="progressBar"></span><span>'+getNiceFileSize(file.size)+'</span>';
var del = tr.insertCell();
del.className='delectBtn';
del.id=file.id +'deleteGif';
del.innerHTML='<a href="javascript:swfu.cancelFile(\'' + file.id + '\')"><img src="/common/upload/SWFUpload/images/del_ico.gif" alt="清除" width="13" height="13" border="0" /></a>';
showInfo(file, listingfiles.rows.length);
}
/**
顯示信息
**/
function showInfo(file,queuelength){
var fileCount = document.getElementById("fileCount");
fileCount.innerText=queuelength;
//var fileTotleSize = document.getElementById("fileTotleSize");
//fileTotleSize.innerText = getNiceFileSize(totalSize);
}
/**
某個上傳文件被取消
**/
function uploadFileCancelled(file, queuelength) {
var listingfiles = document.getElementById("fileList");
var rows = listingfiles.rows;
for(var i=rows.length-1;i>=0;i--){
if(file.id==rows[i].id){
listingfiles.deleteRow(i);
//扣除Filesize
totalSize = totalSize -file.size;
break;
}
}
showInfo(file, listingfiles.rows.length);
}
function uploadFileStart(file, position, queuelength) {
window.status='正在上传文件'+file.name+'....';
}
function uploadProgress(file, bytesLoaded) {
var progress = document.getElementById(file.id + "progress");
var percent = Math.ceil((bytesLoaded / file.size) * 100)
progress.style.backgroundPositionX=(percent-100)+'px';
window.status='已上传'+percent+'%';
//progress.style.background = "#f0f0f0 url(images/progressbar.png) no-repeat -" + (100 - percent) + "px 0";
}
function uploadFileComplete(file) {
var tR = document.getElementById(file.id);
tR.className += " fileUploading";
tR.cells(0).className='flag1';
var progress = document.getElementById(file.id + "progress");
progress.style.backgroundPositionX='0px';
//cancelImage;
var deleteImg = document .getElementById(file.id + 'deleteGif');
deleteImg.innerHTML = "";
onUploadPicture(GetCookie_(escape(file.name)));
DelCookie_(escape(file.name));
}
function uploadError(errno) {
alert(errno)
}
/**
清除所有上傳檔案
**/
function cancelQueue() {
isCancelAll = true;
totalSize = 0;
swfu.cancelQueue();
clearhQueue();
}
/**
處理UI,刪除表格的所有行
**/
function clearhQueue(){
var listingfiles = document.getElementById("fileList");
var rowLength = listingfiles.rows.length;
while(rowLength>0){
listingfiles.deleteRow(0);
rowLength--;
}
}
/**
取消檔案隊列或者隊列上傳完成
**/
function uploadQueueComplete(file) {
//var div = document.getElementById("queueinfo");
if(isCancelAll == true){
// "取消檔案上傳";
showInfo(0,0)
}else{
window.status="上传完毕";
}
}
var _K = 1024;
var _M = _K*1024;
function getNiceFileSize(bitnum){
if(bitnum<_M){
if(bitnum<_K){
return bitnum+'B';
}else{
return Math.ceil(bitnum/_K)+'K';
}
}else{
return Math.ceil(100*bitnum/_M)/100+'M';
}
}
function onUploadPicture(url)
{
var oEditor = parent.FCKeditorAPI.GetInstance('blogJournal.content') ;
oEditor.InsertHtml('<img src=\"'+url+'\"><br>');
}
function changeMode(flag){
if(flag==1){
document.getElementById('multi').style.display='block';
document.getElementById('single').style.display='none';
if(swfu==undefined){
initSwfu();
}
}else{
document.getElementById('multi').style.display='none';
document.getElementById('single').style.display='block';
}
}
</script>
</head>
<body>
<div><a href="#this" onclick="changeMode(1)"><b>多文件上传</b></a> | <a href="#this" onclick="changeMode(2)"><b>单文件上传</b></a></div>
<input type="text" id="subject" style="height: 1px;width: 1px;border: 0">
<div class="all" id="multi" style="display: none;">
<div class="but_01"><a id="browse_link" href="#this"><b>选择图片</b></a>
<a id="clear_all" href="#" onclick="javascript:cancelQueue();"><b>清除所有已选图片</b></a>
</div>
<div id="bg_02">
<div class="file">共<span class="font_red" id="fileCount">0</span> 张图片
<!--共 <span class="font_red" id="fileTotleSize">0K</span>--></div>
<div class="table">
<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#EAEAEA"><strong>图片名称</strong></td>
<td width="150" bgcolor="#EAEAEA"><strong>图片大小</strong></td>
<td width="47" bgcolor="#EAEAEA"><strong>清除</strong></td>
</tr>
</table>
<div id="box" style="overflow:scroll; height:150px; width:100%; font-size: 11px; color: #999999; font-style: normal;">
<table id="fileList" cellpadding="5" cellspacing="1">
</table>
</div>
</div>
</div>
<div class="but_02">
<input type="button" id="upload_link" class="button" name="u" value="上传">
<input type="button" name="close" class="button" onclick="parent.TB_remove();" value="关闭">
</div>
</div>
<div id="single" align="center" style="display: block;">
<iframe name="uFrame" style="display: none;"></iframe>
<form action="/upload.do?uploadKey=${param.uploadKey}&single=1" method="post" target="uFrame" enctype="multipart/form-data" onsubmit="return doSingleUpload(this);">
<input type="file" id="sfiledata" name="filedata" class="button">
<input type="submit" name="upload" class="button" size="25" value="上传">
<input type="button" name="close" class="button" onclick="parent.TB_remove();" value="关闭">
</form>
</div>
</body>
<script type="text/javascript">
function doSingleUpload(frm){
if(frm.filedata.value==''){
alert('请选择要上传的图片');
return false;
}
}
</script>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -