⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io.asp

📁 ZD-BS是一个基于asp+access的个人blog系统 程序特点: 1.数据结构合理
💻 ASP
字号:
<script language="jscript" runat="server">

//============================================================
// Copyright 2006 VAL/ZYI. All Rights Reserved.
//============================================================

function IoClass(){

	this.existFile=function(strPath){
		try{
			var fso=Server.CreateObject("Scripting.FileSystemObject");
		}
		catch(e){return false;}
		try{
			if(!fso.FileExists(Server.MapPath(strPath))) return false;
		}
		catch(e){return false;}
		delete fso;
		return true;
	};

	this.existFolder=function(strPath){
		try{
			var fso=Server.CreateObject("Scripting.FileSystemObject");
		}
		catch(e){return false;}
		try{
			if(!fso.FolderExists(Server.MapPath(strPath))) return false;
		}
		catch(e){return false;}
		delete fso;
		return true;
	};

	this.deleteFile=function(strPath){
		if(this.existFile(strPath)){
			try{
				var fso=Server.CreateObject("Scripting.FileSystemObject");
			}
			catch(e){return false;}
			try{
				fso.DeleteFile(Server.MapPath(strPath));
			}
			catch(e){return false;}
			delete fso;
		}
		return true;
	};

	this.getFile=function(strPath){
		var result=null;
		if(!this.existFolder(strPath)) return null;
		try{
			var fso=Server.CreateObject("Scripting.FileSystemObject");
		}
		catch(e){return null;}
		try{
			var folder=fso.GetFolder(Server.MapPath(strPath));
		}
		catch(e){return null;}
		try{
			var files=folder.Files;
		}
		catch(e){return null;}
		if(files.Count>0){
			var eFiles=new Enumerator(files);
			var objFile=null;
			result=new Array();
			for(var i=0;!eFiles.atEnd();eFiles.moveNext(),i++){
				objFile=eFiles.item();
				result[i]=objFile.Name;
			}
		}
		delete fso;
		return result;
	};

	this.getSubFolder=function(strPath){
		var result=null;
		if(!this.existFolder(strPath)) return null;
		try{
			var fso=Server.CreateObject("Scripting.FileSystemObject");
		}
		catch(e){return null;}
		try{
			var folder=fso.GetFolder(Server.MapPath(strPath));
		}
		catch(e){return null;}
		try{
			var folders=folder.subfolders;
		}
		catch(e){return null;}
		if(folders.Count>0){
			var eFolders=new Enumerator(folders);
			var objFolder=null;
			result=new Array();
			for(var i=0;!eFolders.atEnd();eFolders.moveNext(),i++){
				objFolder=eFolders.item();
				result[i]=objFolder.Name;
			}
		}
		delete fso;
		return result;
	};

	this.readFile=function(strPath,strCharset){
		var result;
		if(!strCharset) strCharset="utf-8";
		if(!this.existFile(strPath)) return false;
		try{
			var objStream=Server.CreateObject("ADODB.Stream");
		}
		catch(e){return false;}
		try{
			objStream.Open();
		}
		catch(e){return false;}
		try{
			objStream.LoadFromFile(Server.MapPath(strPath));
		}
		catch(e){return false;}
		try{
			objStream.Charset=strCharset;
		}
		catch(e){return false;}
		try{
			result=objStream.ReadText();
			objStream.Close();
		}
		catch(e){return false;}
		delete objStream;
		return result;
	};

	this.writeFile=function(strPath,strValue,strCharset){
		if(!strCharset) strCharset="utf-8";
		if(!this.deleteFile(strPath)) return false;
		try{
			var objStream=Server.CreateObject("ADODB.Stream");
		}
		catch(e){return false;}
		try{
			objStream.Open();
		}
		catch(e){return false;}
		try{
			objStream.Charset=strCharset;
		}
		catch(e){return false;}
		try{
			objStream.WriteText(strValue);
		}
		catch(e){return false;}
		try{
			objStream.SaveToFile(Server.MapPath(strPath));
			objStream.Close();
		}
		catch(e){return false;}
		delete objStream;
		return true;
	};

	this.upload=function(strForm,strPath,strName,strType,strMaxSize){
		</script><script language="VBScript" runat="server">
		dim Data_5xsoft
		Class upload_5xsoft
			dim objForm,objFile,Version
			Public function Form(strForm)
				strForm=lcase(strForm)
				if not objForm.exists(strForm) then
					Form=""
				else
					Form=objForm(strForm)
				end if
			end function
			Public function File(strFile)
				strFile=lcase(strFile)
				if not objFile.exists(strFile) then
					set File=new FileInfo
				else
					set File=objFile(strFile)
				end if
			end function
			Private Sub Class_Initialize 
				dim RequestData,sStart,vbCrlf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,theFile
				dim iFileSize,sFilePath,sFileType,sFormValue,sFileName
				dim iFindStart,iFindEnd
				dim iFormStart,iFormEnd,sFormName
				Version="5Soft Version 2.0"
				set objForm=Server.CreateObject("Scripting.Dictionary")
				set objFile=Server.CreateObject("Scripting.Dictionary")
				if Request.TotalBytes<1 then Exit Sub
				set tStream = Server.CreateObject("adodb.stream")
				set Data_5xsoft = Server.CreateObject("adodb.stream")
				Data_5xsoft.Type = 1
				Data_5xsoft.Mode =3
				Data_5xsoft.Open
				Data_5xsoft.Write  Request.BinaryRead(Request.TotalBytes)
				Data_5xsoft.Position=0
				RequestData =Data_5xsoft.Read 
				iFormStart = 1
				iFormEnd = LenB(RequestData)
				vbCrlf = chrB(13) & chrB(10)
				sStart = MidB(RequestData,1, InStrB(iFormStart,RequestData,vbCrlf)-1)
				iStart = LenB (sStart)
				iFormStart=iFormStart+iStart+1
				while (iFormStart + 10) < iFormEnd 
				iInfoEnd = InStrB(iFormStart,RequestData,vbCrlf & vbCrlf)+3
				tStream.Type = 1
				tStream.Mode =3
				tStream.Open
				Data_5xsoft.Position = iFormStart
				Data_5xsoft.CopyTo tStream,iInfoEnd-iFormStart
				tStream.Position = 0
				tStream.Type = 2
				tStream.Charset ="gb2312"
				sInfo = tStream.ReadText
				tStream.Close
				iFormStart = InStrB(iInfoEnd,RequestData,sStart)
				iFindStart = InStr(22,sInfo,"name=""",1)+6
				iFindEnd = InStr(iFindStart,sInfo,"""",1)
				sFormName = lcase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
				if InStr (45,sInfo,"filename=""",1) > 0 then
					set theFile=new FileInfo
					iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
					iFindEnd = InStr(iFindStart,sInfo,"""",1)
					sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
					theFile.FileName=getFileName(sFileName)
					theFile.FilePath=getFilePath(sFileName)
					iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
					iFindEnd = InStr(iFindStart,sInfo,vbCr)
					theFile.FileType =Mid (sinfo,iFindStart,iFindEnd-iFindStart)
					theFile.FileStart =iInfoEnd
					theFile.FileSize = iFormStart -iInfoEnd -3
					theFile.FormName=sFormName
					if not objFile.Exists(sFormName) then
						objFile.add sFormName,theFile
					end if
				else
					tStream.Type =1
					tStream.Mode =3
					tStream.Open
					Data_5xsoft.Position = iInfoEnd 
					Data_5xsoft.CopyTo tStream,iFormStart-iInfoEnd-3
					tStream.Position = 0
					tStream.Type = 2
					tStream.Charset ="gb2312"
						sFormValue = tStream.ReadText 
						tStream.Close
					if objForm.Exists(sFormName) then
						objForm(sFormName)=objForm(sFormName)&", "&sFormValue		  
					else
						objForm.Add sFormName,sFormValue
					end if
				end if
				iFormStart=iFormStart+iStart+1
				wend
				RequestData=""
				set tStream =nothing
			End Sub
			Private Sub Class_Terminate  
				if Request.TotalBytes>0 then
					objForm.RemoveAll
					objFile.RemoveAll
					set objForm=nothing
					set objFile=nothing
					Data_5xsoft.Close
					set Data_5xsoft =nothing
				end if
			End Sub
			Private function GetFilePath(FullPath)
				If FullPath <> "" Then
					GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
				Else
					GetFilePath = ""
				End If
			End  function
			Private function GetFileName(FullPath)
				If FullPath <> "" Then
					GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
				Else
					GetFileName = ""
				End If
			End  function
		End Class
		Class FileInfo
			dim FormName,FileName,FilePath,FileSize,FileType,FileStart
			Private Sub Class_Initialize 
				FileName = ""
				FilePath = ""
				FileSize = 0
				FileStart= 0
				FormName = ""
				FileType = ""
			End Sub
			Public function SaveAs(FullPath)
				dim dr,ErrorChar,i
				SaveAs=true
				if trim(fullpath)="" or FileStart=0 or FileName="" or right(fullpath,1)="/" then exit function
				set dr=CreateObject("Adodb.Stream")
				dr.Mode=3
				dr.Type=1
				dr.Open
				Data_5xsoft.position=FileStart
				Data_5xsoft.copyto dr,FileSize
				dr.SaveToFile FullPath,2
				dr.Close
				set dr=nothing 
				SaveAs=false
			end function
		End Class
		'should use vbs to save Binary
		function uploadFile(strForm,strPath,strName,strType,strMaxSize)
			uploadFile=""
			set upload=new upload_5xsoft
			if upload.objForm.count<>1 then
				uploadFile="err,1"
				exit function
			end if
			set file=upload.file(strForm)
			if file.FileSize<1 or file.FileSize>strMaxSize then
				uploadFile="err,2"
				exit function
			end if
			dim arrType,arrTmp,fileType,mark
			mark=false
			arrType=split(strType,"|")
			arrTmp=split(file.FileName,".")
			fileType=arrTmp(UBound(arrTmp))
			for i=0 to UBound(arrType)
				if fileType=arrType(i) then
					mark=true
				end if
			next
			if mark=false then
				uploadFile="err,3"
				exit function
			end if
			file.saveAs strPath&"/"&strName&"."&fileType
			uploadFile= "done,"+strName&"."&fileType
		end function
		</script><script language="JScript" runat="server">
		return uploadFile(strForm,strPath,strName,strType,strMaxSize);
	};

}
</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -