?? upload.jsp
字號:
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.util.regex.*"%>
<%@ page import="com.jspsmart.upload.*"%>
<%@ page import="net.fiyu.edit.RemotePic"%>
<jsp:useBean id="date" scope="page" class="net.fiyu.edit.TimeStamp"/>
<%@ page import="net.fiyu.edit.UploadWebHelper,net.fiyu.edit.UploadBean"%>
<%!
// 參數變量
String sType, sStyleName;
//' 設置變量
String sAllowExt, sUploadDir,sBaseUrl,sContentPath;
int nAllowSize;
//' 接口變量
String sFileExt,sSaveFileName,sOriginalFileName,sPathFileName,FileName, nFileNum,realpatha;
String sAction;
Connection connect = null;
%>
<%!
/*' ============================================
' 去除Html格式,用于從數據庫中取出值填入輸入框時
' 注意:value="?"這邊一定要用雙引號
' ============================================*/
public String inHTML(String str)
{
String sTemp;
sTemp = str;
if(sTemp.equals(""))
{
System.exit(0);
}
sTemp = sTemp.replaceAll("&", "&");
sTemp = sTemp.replaceAll("<", "<");
sTemp = sTemp.replaceAll(">", ">");
sTemp = sTemp.replaceAll("\"", """);
return sTemp;
}
//初始化上傳限制數據
public void InitUpload(String realpath){
UploadWebHelper uw = new UploadWebHelper();
uw.filename = realpath+"WEB-INF/style.xml";
uw.getInstance();
UploadBean bean = uw.InitPara();
try{
Calendar calendar = Calendar.getInstance();
/*realpatha="/"+calendar.get(Calendar.YEAR)+"/"+(calendar.get(Calendar.MONTH)+1)+"/"+calendar.get(Calendar.DAY_OF_MONTH)+"/"+"upload/";
//圖片和新聞同步,并且將圖片存放在UPLOAD下面
//動態的創建UPLOAD目錄
//java.io.File file=new java.io.File("c:\\aa.txt");
java.io.File picStoreDir=new java.io.File(realpatha);
//do java.io.File.mkdirs()
picStoreDir.mkdirs();
*/
//此處設置上傳文件保存路徑,注意路徑要由ROOT開始=========================
sUploadDir =realpath+"/www/DT_UploadFile/"+calendar.get(Calendar.YEAR) +
"/"+ (calendar.get(Calendar.MONTH)+1) +"/"+ calendar.get(Calendar.DAY_OF_MONTH)+"/";
//修改此處需修改WEB-INF/Style.xml文件對應處<suploaddir>/UploadFile/</suploaddir>=========
//修改此處需修改eWebEditor.jsp文件對應處=========www.ITstudy.cn=========
//sUploadDir = realpath+"articlemanage/article/";
//sUploadDir = bean.getSuploaddir();
//sUploadDir = realpatha;
//System.out.println(sUploadDir);
if(sType.equalsIgnoreCase("remote"))
{
sAllowExt = bean.getSremoteext();
sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
nAllowSize = Integer.parseInt(bean.getSremotesize()) ;
System.out.println(sAllowExt+nAllowSize);
}
else if(sType.equalsIgnoreCase("file"))
{
sAllowExt = bean.getSfileext();
sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
nAllowSize = Integer.parseInt(bean.getSfilesize());
System.out.println(sAllowExt+nAllowSize);
}
else if(sType.equalsIgnoreCase("media"))
{
sAllowExt = bean.getSmediaext();
sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
nAllowSize = Integer.parseInt(bean.getSmediasize());
System.out.println(sAllowExt+nAllowSize);
}
else if(sType.equalsIgnoreCase("flash"))
{
sAllowExt = bean.getSflashext();
sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
nAllowSize = Integer.parseInt(bean.getSflashsize());
System.out.println(sAllowExt+nAllowSize);
}
else
{
sAllowExt = bean.getSimageext();
sAllowExt = sAllowExt + "|" + sAllowExt.toUpperCase();
nAllowSize = Integer.parseInt(bean.getSimagesize());
System.out.println(sAllowExt+nAllowSize);
}
}
catch(Exception e){
}
}
%>
<%
//設置類型
sType=request.getParameter("type");
if(sType==null)
{
sType="image";
}
else
sType=request.getParameter("type").trim();
//設置樣式
sStyleName=request.getParameter("style");
if (sStyleName==null)
{
sStyleName="standard";
}
else
sStyleName=request.getParameter("style").trim();
//設置動作
sAction=request.getParameter("action");
if(sAction==null)
{
sAction="sun";
}
else
sAction=request.getParameter("action").trim();
%>
<%
//初始化上傳變量
InitUpload(config.getServletContext().getRealPath("/"));
//斷開數據庫連接
//sAction = UCase(Trim(Request.QueryString("action"))
if(sAction.equalsIgnoreCase("remote"))
{ //遠程自動獲取
String sContent;
String RemoteFileurl=null;
String Protocol,sUrl;
int Port;
String LocalFileurl=null;
String SrcFileurl=null;
String SaveFileName=null;
sContent=request.getParameter("eWebEditor_UploadText");
if(sContent==null)
{
sContent="sunshanfeng";
}
else
sContent=request.getParameter("eWebEditor_UploadText");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("替換前的html標記為:"+"\n"+sContent);
if(sAllowExt!="")
{
Pattern pRemoteFileurl = Pattern.compile("((http|https|ftp|rtsp|mms):(//|\\\\){1}(([A-Za-z0-9_-])+[.]){1,}(net|com|cn|org|cc|tv|[0-9]{1,3})(\\S*/)((\\S)+[.]{1}("+sAllowExt+")))");//取得網頁上URL的正則表達式
Matcher mRemoteFileurl = pRemoteFileurl.matcher(sContent);//對傳入的字符串進行匹配
Protocol=request.getProtocol();//取得通訊的協議
String ProtocolA[]=Protocol.split("/");//取得協議前面的字母,如HTTP/1.1,變為"HTTP","1.1"
sUrl = ProtocolA[0]+"://"+request.getServerName();//取得本地URL路徑,如http://localhost
//ProtocolA[]=null;
Port=request.getServerPort();//取得端口值
if(Port!=80)
{//查看端口是否為80,如果不是還需要在聯接上加上端口
sUrl=sUrl+":"+Port;
}
String context=request.getContextPath();
sUrl=sUrl+context+"/"+sUploadDir;
System.out.println(sUrl);
StringBuffer sb=new StringBuffer();
boolean result=mRemoteFileurl.find();
int i=0;
while(result)
{
i++;
RemoteFileurl=mRemoteFileurl.group(0);
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("需要替換的遠程連接:"+"\n"+RemoteFileurl);
sOriginalFileName=RemoteFileurl.substring(RemoteFileurl.lastIndexOf("/"));
Pattern pFileType=Pattern.compile("[.]{1}("+sAllowExt+")");//二次匹配取得文件的類型
Matcher mFileType=pFileType.matcher(RemoteFileurl);
while(mFileType.find())
{
String SaveFileType=mFileType.group();
LocalFileurl=sUploadDir+(String)date.Time_Stamp()+i+SaveFileType;//文件的路徑,以時間戳命名
}
String LoadFile=sUploadDir.substring(0,sUploadDir.length()-1); SaveFileName=config.getServletContext().getRealPath("/")+LoadFile+LocalFileurl.substring(LocalFileurl.lastIndexOf("/")+1);
System.out.println();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -