Watermark.java
package cn.com.xunuo.util;
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.awt.image.*;
import javax.swing.*;
import javax.imageio.*;
public class Watermark {
public boolean imgRemark( String filePath) {
String exname = filePath.substring(filePath.lastIndexOf('.')).toLowerCase();
if ( ".jpg.gif.png.jpeg".indexOf(exname)==-1 ) return false;
if ( exname.equals(".gif") && getFrameCount(filePath)>1 ) return false;
ImageIcon imgIcon = null ;
Image theImg = null, waterImg = null;
BufferedImage bimage = null;
Graphics2D g = null;
File srcfile = null;
boolean rt = false;
FileOutputStream out = null;
try{
imgIcon = new ImageIcon(filePath);
theImg = imgIcon.getImage();
int width = theImg.getWidth(null);
int height= theImg.getHeight(null);
String Watermark=WebInfo.getUrlPath()+"WEB-INF/szgywater.png";
srcfile = new File(Watermark);
waterImg = ImageIO.read(srcfile);
int logow = waterImg.getWidth(null); //水印图片的宽;
int logoh = waterImg.getHeight(null); //水印图片的高
double scale=1.0;
/**
if (width>height){
if (height<=3200)
scale = height/7.0/logoh;
}else if (width<=3200)
scale = width*3.0/8.0/logow;
//*/
logow = (int)( logow*scale );
logoh = (int)( logoh*scale );
bimage = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
g = bimage.createGraphics( );
g.drawImage(theImg, 0, 0, null );
g.drawImage(waterImg.getScaledInstance(logow,logoh,Image.SCALE_SMOOTH), width-logow, height-logoh, null );
g.dispose();
try{out = new FileOutputStream(filePath); ImageIO.write(bimage, "JPEG", out); out.close(); rt=true;}catch(Exception e){}
}catch(Exception e){ }
finally{//release...
out=null; g=null; bimage=null; srcfile=null;
waterImg=null; theImg=null; imgIcon=null;/**/
System.gc();
}
return rt;
}
public void copyFile(String oldPath, String newPath) {
try {
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { //Îļþ´æÔÚʱ
InputStream inStream = new FileInputStream(oldPath); //¶ÁÈëÔÎļþ
FileOutputStream fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];
int length;
while ( (byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //×Ö½ÚÊý Îļþ´óС
//System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
fs.close();
inStream.close();
fs=null; inStream=null;//release...
}
oldfile=null;// release...
}
catch (Exception e) { }
}
public static final int STATUS_OK = 0;
public static final int STATUS_FORMAT_ERROR = 1;
/** * File read status: Unable to open source. */
public static final int STATUS_OPEN_ERROR = 2;
protected BufferedInputStream in;
protected int status;
protected int width; // full image width
protected int height; // full image height
protected boolean gctFlag; // global color table used
protected int gctSize; // size of global color table
protected int[] gct; // global color table
protected int[] lct; // local color table
protected int[] act; // active color table
protected int bgIndex; // background color index
protected int bgColor; // background color
protected int lastBgColor; // previous bg color
protected int pixelAspect; // pixel aspect ratio
protected boolean lctFlag; // local color table flag
protected boolean interlace; // interlace flag
protected int lctSize; // local color table size
protected int ix, iy, iw, ih; // current image rectangle
protected Rectangle lastRect; // last image rect
protected BufferedImage image; // current frame
protected BufferedImage lastImage; // previous frame
protected byte[] block = new byte[256]; // current data block
protected int blockSize = 0; // block size
// last graphic control extension info
protected int dispose = 0;
// 0=no action; 1=leave in place; 2=restore to bg; 3=restore to prev
protected int lastDispose = 0;
protected boolean transparency = false; // use transparent color
protected int delay = 0; // delay in milliseconds
protected int transIndex; // transparent color index
// LZW decoder working arrays
protected short[] prefix;
protected byte[] suffix;
protected byte[] pixelStack;
protected byte[] pixels;
protected int frameCount;
static class GifFrame {
public GifFrame(BufferedImage im, int del) {
image = im;
delay = del;
}
public BufferedImage image;
public int delay;
}
public int getFrameCount(String name) {
status = STATUS_OK;
frameCount = 0;
try {
name = name.trim();//.toLowerCase();
in = new BufferedInputStream(new FileInputStream( name ));
gct = null;
lct = null;
if (in != null) {
readHeader();
if (!err()) {
readContents();
if (frameCount < 0) {
status = STATUS_FORMAT_ERROR;
}
}
} else {
status = STATUS_OPEN_ERROR;
}
try {
in.close();
} catch (IOException e) {
}
} catch (IOException e) { status = STATUS_OPEN_ERROR; }
finally{
lastImage=null;
image=null;
in=null;
}
return frameCount;
}
protected boolean err() {
return status != STATUS_OK;
}
protected int gread() {
int curByte = 0;
try {
curByte = in.read();
} catch (IOException e) {
status = STATUS_FORMAT_ERROR;
}
return curByte;
}
protected int readBlock() {
blockSize = gread();
int n = 0;
if (blockSize > 0) {
try {
int count = 0;
while (n < blockSize) {
count = in.read(block, n, blockSize - n);
if (count == -1)
break;
n += count;
}
} catch (IOException e) {
}
if (n < blockSize) {
status = STATUS_FORMAT_ERROR;
}
}
return n;
}
protected int[] readColorTable(int ncolors) {
int nbytes = 3 * ncolors;
int[] tab = null;
byte[] c = new byte[nbytes];
int n = 0;
try {
n = in.read(c);
} catch (IOException e) {
}
if (n < nbytes) {
status = STATUS_FORMAT_ERROR;
} else {
tab = new int[256]; // max size to avoid bounds checks
int i = 0;
int j = 0;
while (i < ncolors) {
int r = ((int) c[j++]) & 0xff;
int g = ((int) c[j++]) & 0xff;
int b = ((int) c[j++]) & 0xff;
tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b;
}
}
return tab;
}
protected void readContents() {
// read GIF file content blocks
boolean done = false;
while (!(done || err())) {
int code = gread();
switch (code) {
case 0x2C : // image separator
readImage();
break;
case 0x21 : // extension
code = gread();
skip();//
break;
case 0x3b : // terminator
done = true;
break;
case 0x00 : // bad byte, but keep going and see what happens
break;
default :
status = STATUS_FORMAT_ERROR;
}
}
}
/** * Reads GIF file header information. */
protected void readHeader() {
String id = "";
for (int i = 0; i < 6; i++) {
id += (char) gread();
}
if (!id.startsWith("GIF")) {
status = STATUS_FORMAT_ERROR;
return;
}
readLSD();
if (gctFlag && !err()) {
gct = readColorTable(gctSize);
bgColor = gct[bgIndex];
}
}
/** * Reads next frame image */
protected void readImage() {
ix = readShort(); // (sub)image position & size
iy = readShort();
iw = readShort();
ih = readShort();
int packed = gread();
lctFlag = (packed & 0x80) != 0; // 1 - local color table flag
interlace = (packed & 0x40) != 0; // 2 - interlace flag
// 3 - sort flag
// 4-5 - reserved
lctSize = 2 << (packed & 7); // 6-8 - local color table size
if (lctFlag) {
lct = readColorTable(lctSize); // read table
act = lct; // make local table active
} else {
act = gct; // make global table active
if (bgIndex == transIndex)
bgColor = 0;
}
int save = 0;
if (transparency) {
save = act[transIndex];
act[transIndex] = 0; // set transparent color if specified
}
if (act == null) {
status = STATUS_FORMAT_ERROR; // no color table defined
}
if (err()) return;
gread(); // decode pixel data
skip();
if (err()) return;
frameCount++;
resetFrame();
}
protected void readLSD() {
// logical screen size
width = readShort();
height = readShort();
// packed fields
int packed = gread();
gctFlag = (packed & 0x80) != 0; // 1 : global color table flag
// 2-4 : color resolution // 5 : gct sort flag
gctSize = 2 << (packed & 7); // 6-8 : gct size
bgIndex = gread(); // background color index
pixelAspect = gread(); // pixel aspect ratio
}
protected int readShort() { // read 16-bit value, LSB first
return gread() | (gread() << 8);
}
protected void resetFrame() {
lastDispose = dispose;
lastRect = new Rectangle(ix, iy, iw, ih);
lastImage = image;
lastBgColor = bgColor;
lct = null;
}
protected void skip() {
do {
readBlock();
} while ((blockSize > 0) && !err());
}
}
WebInfo.java
package cn.com.xunuo.util;
public class WebInfo {
//用来获得到WEB-INF的路径
public static String getUrlPath()
{
/*
Class theClass=ReadXml.class;
String str="";
str=theClass.getClassLoader().getResource("/").getPath();
str=str.replaceAll("%20", " ");
return str;
*/
Class theClass = WebInfo.class;
java.net.URL u = theClass.getResource("");
//str会得到这个函数所在类的路径
String str = u.toString();
//截去一些前面6个无用的字符
str=str.substring(6,str.length());
//将%20换成空格(如果文件夹的名称带有空格的话,会在取得的字符串上变成%20)
str=str.replaceAll("%20", " ");
//查找“WEB-INF”在该字符串的位置
int num = str.indexOf("WEB-INF");
//str=str.substring(0, num+"WEB-INF".length())+"\\"; //Windows
str=str.substring(0, num); //Linux
return str;
// */
}
}
upload.jsp
<%@ page language="java" pageEncoding="utf-8" contentType="text/html;charset=utf-8" %>
<%@ page import="cn.com.xunuo.util.PropertyManager"%>
<%@ page import="cn.com.xunuo.util.*"%>
<%
//Server.ScriptTimeOut = 1800
//参数变量
String sType = null;//文件类型
String sStyleName = null; //样式类型
//设置变量
String sAllowExt = null;//允许的扩展名
long lAllowSize = 0l;//允许的文件大小
String sUploadDir = null ;//上传文件路径
int nUploadObject = 0 ; //上传文件的数量
int nAutoDir = 0;//是否自动选择目录
String sBaseUrl = null; //路径形式 "0" : 相对路径 "1": 根路径格式 "2":存储完整访问路径
String sContentPath = null;//附件目录
//接口变量
String sFileExt;//文件扩展名
String sOriginalFileName = null;//源文件名
String sSaveFileName = null;//存储文件名
String sPathFileName = null;//文件路径
int nFileNum = 0; //文件数量
//Call DBConnBegin() ' 初始化数据库连接
//Call InitUpload() ' 初始化上传变量
//Call DBConnEnd() ' 断开数据库连接
String sAction = null;
sAction = request.getParameter("action");
sAction = sAction!=null?sAction.trim().toLowerCase():sAction;
sType = request.getParameter("type");
sStyleName = request.getParameter("style");
sUploadDir = PropertyManager.getProperty("Cms.UploadPath");//保存路径
sBaseUrl = "1";
sContentPath = PropertyManager.getProperty("Cms.UploadPath");
if (sBaseUrl.equals("0"))
{
sContentPath = "" ;
}
if (sBaseUrl.equals("1"))
{
sContentPath = sUploadDir ;
}
if (sBaseUrl.equals("2"))
{
sContentPath = "完整访问路径";
}
//设置允许上传的文件扩展名
if (sType.equals("remote"))
{
sAllowExt = "gif|jpg|jpeg|bmp|png";
lAllowSize = 100*1024*1024;//10M
}else if (sType.equals("file"))
{
sAllowExt = "rar|zip|exe|doc|xls|chm|hlp";
lAllowSize = 10*1024*1024;//10M
}else if (sType.equals("flash"))
{
sAllowExt = "swf";
lAllowSize = 100*1024*1024;//100M
}else if (sType.equals("media"))
{
sAllowExt = "rm|mp3|wav|mid|midi|ra|avi|mpg|mpeg|asf|asx|wma|mov|rmvb";
lAllowSize = 1000*1024*1024;//100M
}else if (sType.equals("image"))
{
sAllowExt = "gif|jpg|jpeg|bmp|png";
lAllowSize = 100*1024*1024;//100M
}else
{
sAllowExt = "gif|jpg|jpeg|bmp|png";
lAllowSize = 100*1024*1024;//100M
}
/*Select Case sAction
Case "REMOTE"
Call DoRemote() ' 远程自动获取
Case "SAVE"
Call ShowForm() ' 显示上传表单
Call DoSave() ' 存文件
Case Else
Call ShowForm() ' 显示上传表单
End Select
public void ShowForm()
{*/
if (sAction!=null && sAction.equals("remote"))
{
/**如果设置了远程文件自动保存,提交到服务器前,会先将远程文件保存到本地:如图片可以先保存到本地
*如有链接:http://localhost:8080/test.gif
*程序会先将数据存取到指定目录下,然后将路径改成Editor设置的路径*/
}else
{
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<HTML>
<HEAD>
<TITLE>文件上传</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body, a, table, div, span, td, th, input, select{font:9pt;font-family: "宋体", Verdana, Arial, Helvetica, sans-serif;}
body {padding:0px;margin:0px}
</style>
<script language="JavaScript" src="./dialog/dialog.js"></script>
</head>
<body bgcolor="menu">
<form action="upload.jsp?action=save&type=<%=sType%>&style=<%=sStyleName%>" method="post" name="myform" enctype="multipart/form-data">
<input type=file name="uploadfile" size=1 style="width:100%" onChange="originalfile.value=this.value">
<input type="hidden" name="originalfile" value="">
<input type="hidden" name="needmark" id="needmark" value="1">
</form>
<script language=javascript>
var sAllowExt = "<%=sAllowExt%>";
// 检测上传表单
function CheckUploadForm() {
if (!IsExt(document.myform.uploadfile.value,sAllowExt)){
parent.UploadError("提示:\n\n请选择一个有效的文件,\n支持的格式有("+sAllowExt+")!");
return false;
}
return true
}
// 提交事件加入检测表单
var oForm = document.myform ;
oForm.attachEvent("onsubmit", CheckUploadForm) ;
if (! oForm.submitUpload) oForm.submitUpload = new Array() ;
oForm.submitUpload[oForm.submitUpload.length] = CheckUploadForm ;
if (! oForm.originalSubmit) {
oForm.originalSubmit = oForm.submit ;
oForm.submit = function() {
if (this.submitUpload) {
for (var i = 0 ; i < this.submitUpload.length ; i++) {
this.submitUpload[i]() ;
}
}
this.originalSubmit() ;
}
}
// 上传表单已装入完成
try {
parent.UploadLoaded();
}
catch(e){
}
</script>
</body>
</html>
<%
//System.out.println(sAction);
if (sAction!=null && sAction.equals("save"))
{
//调用SmartUpload实现文件上传功能
//上传成功之后,改变父窗口
//上载附件
String strFileName = null;
String strExtName = null;
String strTmp = null;
java.util.Date nowDate = new java.util.Date(System.currentTimeMillis());
%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/>
<%
//************upload start****************************
mySmartUpload.initialize(pageContext);
//sContentPath = request.getContextPath() + sContentPath;
//mySmartUpload.setTotalMaxFileSize(lAllowSize);
//System.out.println("tttt" + sContentPath);
try {
mySmartUpload.upload();
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
if (!myFile.isMissing())
{
strTmp = Long.toString(nowDate.getTime()); //获取当前时间
strFileName = myFile.getFileName();
sOriginalFileName = strFileName; //获取上载文件原始名称
strExtName = strFileName.substring(strFileName.lastIndexOf('.')); //获取上载文件的扩展名
sSaveFileName = strTmp + strExtName; //生成一个新文件名(当前时间)
sSaveFileName = sSaveFileName.toLowerCase();
sPathFileName = sContentPath + sSaveFileName;
// Save the files with its original names in a virtual path of the web server
//System.out.println("ccccccccc"+application.getRealPath(sContentPath));
myFile.saveAs(application.getRealPath(sContentPath) + "\\"+ sSaveFileName,mySmartUpload.SAVE_AUTO);
String myfn=WebInfo.getUrlPath()+"temp/editer/"+sSaveFileName;
sSaveFileName = request.getContextPath() + "/" +sSaveFileName;
sPathFileName = request.getContextPath() + sPathFileName;
//System.out.println(sSaveFileName+"=============="+sPathFileName);
//myFile.saveAs("/temp/cms" + "\\"+ sSaveFileName,mySmartUpload.SAVE_AUTO);
String markWater=mySmartUpload.getRequest().getParameter("needmark");
if("1".equals(markWater)){
Watermark wm=new Watermark();
wm.imgRemark(myfn);
}
}
}// end for
}// end try
catch(Exception e){
//将Exception对象中的错误信息打印到网页上来
System.out.println(e.toString());
java.io.StringWriter myout = new java.io.StringWriter();
e.printStackTrace(new java.io.PrintWriter(myout));
String trace = myout.toString();
out.print("<pre>"+trace+"</pre>");
String message = "<font color=\"#ff0000\">发生错误!</font>";
out.print(message);
}// end catch
%>
<SCRIPT LANGUAGE="JavaScript">
<!--
parent.UploadSaved("<%=sPathFileName%>");
var obj=parent.dialogArguments.dialogArguments;
if (!obj) obj=parent.dialogArguments;
try
{
obj.addUploadFile("<%=sOriginalFileName%>","<%=sSaveFileName%>","<%=sPathFileName%>");
}
catch(e){}
//-->
</SCRIPT>
<%
}
}%>
<%
jspWriter = out;
%>
<%!
private JspWriter jspWriter;
/*public String GetRndFileName(String sExt)
{
String strReturn;
strReturn = String.valueOf(System.currentTimeMillis()) + "." + sExt;
return strReturn;
}
//输出客户端脚本
public void OutScript(String str)
{
jspWriter.println("<script language=javascript>" + str + ";history.back()</script>");
}
public void OutScriptNoBack(String str)
{
jspWriter.println("<script language=javascript>" + str + "</script>");
}*/
/*public void DoSave()
{
//默认无组件上传类
//Call DoUpload_Class
sPathFileName = sContentPath + sSaveFileName;
OutScript("parent.UploadSaved('" & sPathFileName & "');var obj=parent.dialogArguments.dialogArguments;if (!obj) obj=parent.dialogArguments;try{obj.addUploadFile('" & sOriginalFileName & "', '" & sSaveFileName & "', '" & sPathFileName & "');} catch(e){}");
}*/
/*自动获取远程文件
public void DoRemote()
{
Dim sContent, i
For i = 1 To Request.Form("eWebEditor_UploadText").Count
sContent = sContent & Request.Form("eWebEditor_UploadText")(i)
Next
If sAllowExt <> "" Then
sContent = ReplaceRemoteUrl(sContent, sAllowExt)
End If
Response.Write "<HTML><HEAD><TITLE>远程上传</TITLE><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body>" & _
"<input type=hidden id=UploadText value=""" & inHTML(sContent) & """>" & _
"</body></html>"
Call OutScriptNoBack("parent.setHTML(UploadText.value);try{parent.addUploadFile('" & sOriginalFileName & "', '" & sSaveFileName & "', '" & sPathFileName & "');} catch(e){} parent.remoteUploadOK();")
}*/
/*
public void DoUpload_Class()
{
On Error Resume Next
Dim oUpload, oFile
' 建立上传对象
Set oUpload = New upfile_class
' 取得上传数据,限制最大上传
oUpload.GetData(nAllowSize*1024)
If oUpload.Err > 0 Then
Select Case oUpload.Err
Case 1
Call OutScript("parent.UploadError('请选择有效的上传文件!')")
Case 2
Call OutScript("parent.UploadError('你上传的文件总大小超出了最大限制(" & nAllowSize & "KB)!')")
End Select
Response.End
End If
Set oFile = oUpload.File("uploadfile")
sFileExt = LCase(oFile.FileExt)
Call CheckValidExt(sFileExt)
sOriginalFileName = oFile.FileName
sSaveFileName = GetRndFileName(sFileExt)
oFile.SaveToFile Server.Mappath(sUploadDir & sSaveFileName)
Set oFile = Nothing
Set oUpload = Nothing
}*/
/*public String GetRndFileName(String sExt)
{
String strReturn;
strReturn = String.valueOf(System.currentTimeMillis()) + "." + sExt;
return strReturn;
}
//输出客户端脚本
public void OutScript(String str)
{
out.println("<script language=javascript>" & str & ";history.back()</script>");
}
public void OutScriptNoBack(str)
{
out.println("<script language=javascript>" & str & "</script>");
}
*/
/*检测扩展名的有效性
public void CheckValidExt(String sExt)
{
Dim b, i, aExt
b = False
aExt = Split(sAllowExt, "|")
For i = 0 To UBound(aExt)
If LCase(aExt(i)) = sExt Then
b = True
Exit For
End If
Next
If b = False Then
OutScript("parent.UploadError('提示:\n\n请选择一个有效的文件,\n支持的格式有("+sAllowExt+")!')")
Response.End
End If
}*/
/*
// 转为根路径格式
Function RelativePath2RootPath(url)
Dim sTempUrl
sTempUrl = url
If Left(sTempUrl, 1) = "/" Then
RelativePath2RootPath = sTempUrl
Exit Function
End If
Dim sWebEditorPath
sWebEditorPath = Request.ServerVariables("SCRIPT_NAME")
sWebEditorPath = Left(sWebEditorPath, InstrRev(sWebEditorPath, "/") - 1)
Do While Left(sTempUrl, 3) = "../"
sTempUrl = Mid(sTempUrl, 4)
sWebEditorPath = Left(sWebEditorPath, InstrRev(sWebEditorPath, "/") - 1)
Loop
RelativePath2RootPath = sWebEditorPath & "/" & sTempUrl
End Function
*/
/*根路径转为带域名全路径格式
Function RootPath2DomainPath(url)
Dim sHost, sPort
sHost = Split(Request.ServerVariables("SERVER_PROTOCOL"), "/")(0) & "://" & Request.ServerVariables("HTTP_HOST")
sPort = Request.ServerVariables("SERVER_PORT")
If sPort <> "80" Then
sHost = sHost & ":" & sPort
End If
RootPath2DomainPath = sHost & url
End Function*/
//================================================
//作 用:替换字符串中的远程文件为本地文件并保存远程文件
//参 数:
// sHTML : 要替换的字符串
// sExt : 执行替换的扩展名
//================================================
/*Function ReplaceRemoteUrl(sHTML, sExt)
Dim s_Content
s_Content = sHTML
If IsObjInstalled("Microsoft.XMLHTTP") = False then
ReplaceRemoteUrl = s_Content
Exit Function
End If
Dim re, RemoteFile, RemoteFileurl, SaveFileName, SaveFileType
Set re = new RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = "((http|https|ftp|rtsp|mms):(\/\/|\\\\){1}(([A-Za-z0-9_-])+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(\S*\/)((\S)+[.]{1}(" & sExt & ")))"
Set RemoteFile = re.Execute(s_Content)
Dim a_RemoteUrl(), n, i, bRepeat
n = 0
' 转入无重复数据
For Each RemoteFileurl in RemoteFile
If n = 0 Then
n = n + 1
Redim a_RemoteUrl(n)
a_RemoteUrl(n) = RemoteFileurl
Else
bRepeat = False
For i = 1 To UBound(a_RemoteUrl)
If UCase(RemoteFileurl) = UCase(a_RemoteUrl(i)) Then
bRepeat = True
Exit For
End If
Next
If bRepeat = False Then
n = n + 1
Redim Preserve a_RemoteUrl(n)
a_RemoteUrl(n) = RemoteFileurl
End If
End If
Next
' 开始替换操作
nFileNum = 0
For i = 1 To n
SaveFileType = Mid(a_RemoteUrl(i), InstrRev(a_RemoteUrl(i), ".") + 1)
SaveFileName = GetRndFileName(SaveFileType)
If SaveRemoteFile(SaveFileName, a_RemoteUrl(i)) = True Then
nFileNum = nFileNum + 1
If nFileNum > 0 Then
sOriginalFileName = sOriginalFileName & "|"
sSaveFileName = sSaveFileName & "|"
sPathFileName = sPathFileName & "|"
End If
sOriginalFileName = sOriginalFileName & Mid(a_RemoteUrl(i), InstrRev(a_RemoteUrl(i), "/") + 1)
sSaveFileName = sSaveFileName & SaveFileName
sPathFileName = sPathFileName & sContentPath & SaveFileName
s_Content = Replace(s_Content, a_RemoteUrl(i), sContentPath & SaveFileName, 1, -1, 1)
End If
Next
ReplaceRemoteUrl = s_Content
End Function
*/
/*
//================================================
//作 用:保存远程的文件到本地
//参 数:s_LocalFileName ------ 本地文件名
// s_RemoteFileUrl ------ 远程文件URL
//返回值:True ----成功
// False ----失败
//================================================
Function SaveRemoteFile(s_LocalFileName, s_RemoteFileUrl)
Dim Ads, Retrieval, GetRemoteData
Dim bError
bError = False
SaveRemoteFile = False
On Error Resume Next
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", s_RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
If LenB(GetRemoteData) > nAllowSize*1024 Then
bError = True
Else
Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile Server.MapPath(sUploadDir & s_LocalFileName), 2
.Cancel()
.Close()
End With
Set Ads=nothing
End If
If Err.Number = 0 And bError = False Then
SaveRemoteFile = True
Else
Err.Clear
End If
End Function
*/
//================================================
//作 用:检查组件是否已经安装
//参 数:strClassString ----组件名
//返回值:True ----已经安装
// False ----没有安装
//================================================
/*
Function IsObjInstalled(strClassString)
On Error Resume Next
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End Function
*/
%>
img.htm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 FINAL//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
body, a, table, div, span, td, th, input, select{font:9pt;font-family: "宋体", Verdana, Arial, Helvetica, sans-serif;}
body {padding:5px}
</style>
<script language="JavaScript" src="dialog.js"></script>
<script language="JavaScript">
var sAction = "INSERT";
var sTitle = "插入";
var oControl;
var oSeletion;
var sRangeType;
var sFromUrl = "http://";
var sAlt = "";
var sBorder = "0";
var sBorderColor = "";
var sFilter = "";
var sAlign = "";
var sWidth = "";
var sHeight = "";
var sVSpace = "";
var sHSpace = "";
var sCheckFlag = "file";
oSelection = dialogArguments.eWebEditor.document.selection.createRange();
sRangeType = dialogArguments.eWebEditor.document.selection.type;
if (sRangeType == "Control") {
if (oSelection.item(0).tagName == "IMG"){
sAction = "MODI";
sTitle = "修改";
sCheckFlag = "url";
oControl = oSelection.item(0);
sFromUrl = oControl.getAttribute("src", 2);
sAlt = oControl.alt;
sBorder = oControl.border;
sBorderColor = oControl.style.borderColor;
sFilter = oControl.style.filter;
sAlign = oControl.align;
sWidth = oControl.width;
sHeight = oControl.height;
sVSpace = oControl.vspace;
sHSpace = oControl.hspace;
}
}
document.write("<title>图片属性(" + sTitle + ")</title>");
// 初始值
function InitDocument(){
SearchSelectValue(d_filter, sFilter);
SearchSelectValue(d_align, sAlign.toLowerCase());
d_fromurl.value = sFromUrl;
d_alt.value = sAlt;
d_border.value = sBorder;
d_bordercolor.value = sBorderColor;
s_bordercolor.style.backgroundColor = sBorderColor;
d_width.value = sWidth;
d_height.value = sHeight;
d_vspace.value = sVSpace;
d_hspace.value = sHSpace;
}
// 图片来源单选点击事件
function RadioClick(what){
if (what=="url"){
d_checkfromfile.checked=false;
d_fromurl.disabled=false;
d_checkfromurl.checked=true;
d_file.myform.uploadfile.disabled=true;
}else{
d_checkfromurl.checked=false;
d_file.myform.uploadfile.disabled=false;
d_checkfromfile.checked=true;
d_fromurl.disabled=true;
}
}
// 上传帧调入完成时执行
function UploadLoaded(){
// 初始radio
RadioClick(sCheckFlag);
}
// 上传错误
function UploadError(sErrDesc){
AbleItems();
RadioClick('file');
divProcessing.style.display="none";
try {
BaseAlert(d_file.myform.uploadfile,sErrDesc);
}
catch(e){}
}
// 文件上传完成时执行,带入上传文件名
function UploadSaved(sPathFileName){
d_fromurl.value = sPathFileName;
ReturnValue();
}
// 本窗口返回值
function ReturnValue(){
sFromUrl = d_fromurl.value;
sAlt = d_alt.value;
sBorder = d_border.value;
sBorderColor = d_bordercolor.value;
sFilter = d_filter.options[d_filter.selectedIndex].value;
sAlign = d_align.value;
sWidth = d_width.value;
sHeight = d_height.value;
sVSpace = d_vspace.value;
sHSpace = d_hspace.value;
if (sAction == "MODI") {
oControl.src = sFromUrl;
oControl.alt = sAlt;
oControl.border = sBorder;
oControl.style.borderColor = sBorderColor;
oControl.style.filter = sFilter;
oControl.align = sAlign;
oControl.width = sWidth;
oControl.height = sHeight;
oControl.style.width = sWidth;
oControl.style.height = sHeight;
oControl.vspace = sVSpace;
oControl.hspace = sHSpace;
}else{
var sHTML = '';
if (sFilter!=""){
sHTML=sHTML+'filter:'+sFilter+';';
}
if (sBorderColor!=""){
sHTML=sHTML+'border-color:'+sBorderColor+';';
}
if (sHTML!=""){
sHTML=' style="'+sHTML+'"';
}
sHTML = '<img id=eWebEditor_TempElement_Img src="'+sFromUrl+'"'+sHTML;
if (sBorder!=""){
sHTML=sHTML+' border="'+sBorder+'"';
}
if (sAlt!=""){
sHTML=sHTML+' alt="'+sAlt+'"';
}
if (sAlign!=""){
sHTML=sHTML+' align="'+sAlign+'"';
}
if (sWidth!=""){
sHTML=sHTML+' width="'+sWidth+'"';
}
if (sHeight!=""){
sHTML=sHTML+' height="'+sHeight+'"';
}
if (sVSpace!=""){
sHTML=sHTML+' vspace="'+sVSpace+'"';
}
if (sHSpace!=""){
sHTML=sHTML+' hspace="'+sHSpace+'"';
}
sHTML=sHTML+'>';
dialogArguments.insertHTML(sHTML);
var oTempElement = dialogArguments.eWebEditor.document.getElementById("eWebEditor_TempElement_Img");
oTempElement.src = sFromUrl;
oTempElement.removeAttribute("id");
}
window.returnValue = null;
window.close();
}
function needmarkdeal(){
try{
if(d_waterprint.checked){
d_file.myform.needmark.value="1";
}else{
d_file.myform.needmark.value="";
}
}catch(err){
alert(err.description);
}
}
// 点确定时执行
function ok(){
// 数字型输入的有效性
d_border.value = ToInt(d_border.value);
d_width.value = ToInt(d_width.value);
d_height.value = ToInt(d_height.value);
d_vspace.value = ToInt(d_vspace.value);
d_hspace.value = ToInt(d_hspace.value);
if(d_waterprint.checked){
d_file.myform.needmark.value="1";
}else{
d_file.myform.needmark.value="";
}
// 边框颜色的有效性
if (!IsColor(d_bordercolor.value)){
BaseAlert(d_bordercolor,'提示:\n\n无效的边框颜色值!');
return false;
}
if (d_checkfromurl.checked){
// 返回值
ReturnValue();
}else{
// 上传文件判断
if (!d_file.CheckUploadForm()) return false;
// 使各输入框无效
DisableItems();
// 显示正在上传图片
divProcessing.style.display="";
// 上传表单提交
d_file.myform.submit();
}
}
// 使所有输入框无效
function DisableItems(){
d_checkfromfile.disabled=true;
d_checkfromurl.disabled=true;
d_fromurl.disabled=true;
d_alt.disabled=true;
d_border.disabled=true;
d_bordercolor.disabled=true;
d_filter.disabled=true;
d_align.disabled=true;
d_width.disabled=true;
d_height.disabled=true;
d_vspace.disabled=true;
d_hspace.disabled=true;
Ok.disabled=true;
}
// 使所有输入框有效
function AbleItems(){
d_checkfromfile.disabled=false;
d_checkfromurl.disabled=false;
d_fromurl.disabled=false;
d_alt.disabled=false;
d_border.disabled=false;
d_bordercolor.disabled=false;
d_filter.disabled=false;
d_align.disabled=false;
d_width.disabled=false;
d_height.disabled=false;
d_vspace.disabled=false;
d_hspace.disabled=false;
Ok.disabled=false;
}
</script>
<BODY bgColor=menu onLoad="InitDocument()">
<table border=0 cellpadding=0 cellspacing=0 align=center>
<tr>
<td>
<fieldset>
<legend>图片来源</legend>
<table border=0 cellpadding=0 cellspacing=0>
<tr><td colspan=9 height=5></td></tr>
<tr>
<td width=7></td>
<td width=54 align=right onClick="RadioClick('file')"><input type=radio id="d_checkfromfile" value="1" onClick="RadioClick('file')">上传:</td>
<td width=5></td>
<td colspan=5>
<script Language=JavaScript>
document.write('<iframe id=d_file frameborder=0 src="../upload.jsp?type=image&style=' +config.StyleName + '" width="100%" height="22" scrolling=no></iframe>');
</Script>
</td>
<td width=7></td>
</tr>
<tr><td colspan=9 height=5></td></tr>
<tr>
<td width=7></td>
<td width=54 align=right onClick="RadioClick('url')"><input type=radio id="d_checkfromurl" value="1" onClick="RadioClick('url')">网络:</td>
<td width=5></td>
<td colspan=5><input type=text id="d_fromurl" style="width:243px" size=30 value=""></td>
<td width=7></td>
</tr>
<tr><td colspan=9 height=5></td></tr>
</table>
</fieldset>
</td>
</tr>
<tr><td height=5></td></tr>
<tr>
<td>
<fieldset>
<legend>显示效果</legend>
<table border=0 cellpadding=0 cellspacing=0>
<tr><td colspan=9 height=5></td></tr>
<tr>
<td width=7></td>
<td>说明文字:</td>
<td width=5></td>
<td colspan=5><input type=text id=d_alt size=38 value="" style="width:243px"></td>
<td width=7></td>
</tr>
<tr><td colspan=9 height=5></td></tr>
<tr>
<td width=7></td>
<td noWrap>边框粗细:</td>
<td width=5></td>
<td><input type=text id=d_border size=10 value="" ONKEYPRESS="event.returnValue=IsDigit();"></td>
<td width=40></td>
<td noWrap>边框颜色:</td>
<td width=5></td>
<td><table border=0 cellpadding=0 cellspacing=0><tr><td><input type=text id=d_bordercolor size=7 value=""></td><td><img border=0 src="../sysimage/rect.gif" width=18 style="cursor:hand" id=s_bordercolor onClick="SelectColor('bordercolor')"></td></tr></table></td>
<td width=7></td>
</tr>
<tr><td colspan=9 height=5></td></tr>
<tr>
<td width=7></td>
<td>特殊效果:</td>
<td width=5></td>
<td>
<select id=d_filter style="width:72px" size=1>
<option value='' selected>无</option>
<option value='Alpha(Opacity=50)'>半透明</option>
<option value='Alpha(Opacity=0, FinishOpacity=100, Style=1, StartX=0, StartY=0, FinishX=100, FinishY=140)'>线型透明</option>
<option value='Alpha(Opacity=10, FinishOpacity=100, Style=2, StartX=30, StartY=30, FinishX=200, FinishY=200)'>放射透明</option>
<option value='blur(add=1,direction=14,strength=15)'>模糊效果</option><option value='blur(add=true,direction=45,strength=30)'>风动模糊</option>
<option value='Wave(Add=0, Freq=60, LightStrength=1, Phase=0, Strength=3)'>正弦波纹</option>
<option value='gray'>黑白照片</option><option value='Chroma(Color=#FFFFFF)'>白色透明</option>
<option value='DropShadow(Color=#999999, OffX=7, OffY=4, Positive=1)'>投射阴影</option>
<option value='Shadow(Color=#999999, Direction=45)'>阴影</option>
<option value='Glow(Color=#ff9900, Strength=5)'>发光</option>
<option value='flipv'>垂直翻转</option>
<option value='fliph'>左右翻转</option>
<option value='grays'>降低彩色</option>
<option value='xray'>X光照片</option>
<option value='invert'>底片</option>
</select>
</td>
<td width=40></td>
<td>对齐方式:</td>
<td width=5></td>
<td>
<select id=d_align size=1 style="width:72px">
<option value='' selected>默认</option>
<option value='left'>居左</option>
<option value='right'>居右</option>
<option value='top'>顶部</option>
<option value='middle'>中部</option>
<option value='bottom'>底部</option>
<option value='absmiddle'>绝对居中</option>
<option value='absbottom'>绝对底部</option>
<option value='baseline'>基线</option>
<option value='texttop'>文本顶部</option>
</select>
</td>
<td width=7></td>
</tr>
<tr><td colspan=9 height=5></td></tr>
<tr>
<td width=7></td>
<td>图片宽度:</td>
<td width=5></td>
<td><input type=text id=d_width size=10 value="" ONKEYPRESS="event.returnValue=IsDigit();" maxlength=4></td>
<td width=40></td>
<td>图片高度:</td>
<td width=5></td>
<td><input type=text id=d_height size=10 value="" ONKEYPRESS="event.returnValue=IsDigit();" maxlength=4></td>
<td width=7></td>
</tr>
<tr><td colspan=9 height=5></td></tr>
<tr>
<td width=7></td>
<td>上下间距:</td>
<td width=5></td>
<td><input type=text id=d_vspace size=10 value="" ONKEYPRESS="event.returnValue=IsDigit();" maxlength=2></td>
<td width=40></td>
<td>左右间距:</td>
<td width=5></td>
<td><input type=text id=d_hspace size=10 value="" ONKEYPRESS="event.returnValue=IsDigit();" maxlength=2></td>
<td width=7></td>
</tr>
<tr>
<td width=7></td>
<td align="right">加水印:</td>
<td width=5></td>
<td><input type=checkbox id=d_waterprint value="1" checked="checked" onClick="needmarkdeal();" ></td>
<td width=40></td>
<td> </td>
<td width=5></td>
<td> </td>
<td width=7></td>
</tr>
<tr><td colspan=9 height=5></td></tr>
</table>
</fieldset>
</td>
</tr>
<tr><td height=5></td></tr>
<tr><td align=right><input type=submit value=' 确定 ' id=Ok onClick="ok()"> <input type=button value=' 取消 ' onClick="window.close();"></td></tr>
</table>
<div id=divProcessing style="width:200px;height:30px;position:absolute;left:70px;top:100px;display:none">
<table border=0 cellpadding=0 cellspacing=1 bgcolor="#000000" width="100%" height="100%"><tr><td bgcolor=#3A6EA5><marquee align="middle" behavior="alternate" scrollamount="5"><font color=#FFFFFF>...图片上传中...请等待...</font></marquee></td></tr></table>
</div>
</body>
</html>