仓酷云

标题: ASP编程:不必WinRar将收集空间上的文件打包下载... [打印本页]

作者: 透明    时间: 2015-1-16 22:11
标题: ASP编程:不必WinRar将收集空间上的文件打包下载...
ActiveServerPage技术为应用开发商提供了基于脚本的直观、快速、高效的应用开发手段,极大地提高了开发的效果。在讨论ASP的安全性问题之前,让我们来看看ASP是怎么工作的。winrar|打包|收集|下载此办法,不倡议紧缩,年夜文件,
一样平常的小文件压几个还很好用的
<%@Language=VBScript%>
<%OptionExplicit%>
<!--#includefile="asptar.asp"-->
<%
Response.Buffer=True
Response.Clear
DimCo,Temp,T,x,i,fsoBrowse,theFolder,TheSubFolders,FilePath,s,PH,objTar
Co=0
PH="./UpFile"文件路径紧缩Upfile下的一切文件
SetobjTar=NewTarball
objTar.TarFilename="LvBBS_UpdateFile.rar"打包的称号
objTar.Path=PH
setfsoBrowse=CreateObject("Scripting.FileSystemObject")
SettheFolder=fsoBrowse.GetFolder(Server.Mappath(PH))
SettheSubFolders=theFolder.SubFolders
ForEachTintheFolder.Files
Temp=Temp&T.Name&"|"
Co=Co+1
Next
ForEachxIntheSubFolders
ForEachiInX.Files
Temp=Temp&X.Name&"/"&i.Name&"|"
Co=Co+1
Next
Next
IfCo<1Then
Response.Write"临时没有可更新的文件下载"
objTar.AddMemoryFile"Sorry.txt","NotFile!"
Else
Temp=Left(Temp,Len(Temp)-1)
FilePath=Split(Temp,"|")
Fors=0ToUbound(FilePath)
objTar.AddFileServer.Mappath(PH&"/"&FilePath(s))
Next
IfResponse.IsClientConnectedThen
objTar.WriteTar
Response.Flush
EndIf
EndIf
SetObjTar=Nothing
SetfsoBrowse=Nothing
SettheFolder=Nothing
SettheSubFolders=Nothing
%>
asptar.asp
<%
UNIXTarballcreator
====================
Author:ChrisRead
Version:1.0.1
====================
Homepage:http://users.bigpond.net.au/mrjolly/

Thisclassprovidestheabilitytoarchivemultiplefilestogetherintoasingle
distributablefilecalledatarball(TheTARactuallystandsforTapeARchive).
ThesearecommonUNIXfileswhichcontainuncompresseddata.

Sowhatisthisusefulfor?Well,itallowsyoutoeffectivelycombinemultiple
filesintoasinglefilefordownloading.TheTARfilesarereadableandextractable
byawidevarietyoftools,includingtheverywidelydistributedWinZip.

Thisscriptcanincludetwotypesofdataineacharchive,filedatareadfromadisk,
andalsothingsdirectfrommemory,likefromastring.Thearchivessupportfilesin
abinarystructure,soyoucanstoreexecutablefilesifyouneedto,orjuststore
text.

Thisclasswasdevelopedtoassistmewithafewprojectsandhasgrownwithevery
implementation.CurrentlyIusethisclasstotarballXMLdataforarchivalpurposes
whichallowsmetograb100sofdynamicallycreatedXMLfilesinasingledownload.

Thereareasmallnumberofpropertiesandmethods,whichareoutlinedinthe
accompanyingdocumentation.

ClassTarball
PublicTarFilenameResultanttarballfilename

PublicUserIDUNIXuserID
PublicUserNameUNIXusername
PublicGroupIDUNIXgroupID
PublicGroupNameUNIXgroupname

PublicPermissionsUNIXpermissions

PublicBlockSizeBlockbytesizeforthetarball(default=512)
PublicIgnorePathsIgnoreanysuppliedpathsforthetarballoutput
PublicBasePathInsertabasepathwitheachfile
PublicPath
Storageforfileinformation
PrivateobjFiles,TmpFileName
PrivateobjMemoryFiles

Filelistmanagementsubs,verybasicstuff
PublicSubAddFile(sFilename)
objFiles.AddsFilename,sFilename
EndSub

PublicSubRemoveFile(sFilename)
objFiles.RemovesFilename
EndSub

PublicSubAddMemoryFile(sFilename,sContents)
objMemoryFiles.AddsFilename,sContents
EndSub

PublicSubRemoveMemoryFile(sFilename)
objMemoryFiles.RemovesFilename
EndSub
Sendthetarballtothebrowser
PublicSubWriteTar()
DimobjStream,objInStream,lTemp,aFiles
SetobjStream=Server.CreateObject("ADODB.Stream")Themainstream
SetobjInStream=Server.CreateObject("ADODB.Stream")Theinputstreamfordata

objStream.Type=2
objStream.Charset="x-ansi"GoodoldextendedASCII
objStream.Open
objInStream.Type=2
objInStream.Charset="x-ansi"
Gothroughallfilesstoredondiskfirst
aFiles=objFiles.Items

ForlTemp=0toUBound(aFiles)
objInStream.Open
objInStream.LoadFromFileaFiles(lTemp)
objInStream.Position=0
ExportFileaFiles(lTemp),objStream,objInStream
TmpFileName=replace(aFiles(lTemp),Server.Mappath(Path)&"","")
ExportFileTmpFileName,objStream,objInStream
objInStream.Close
Next
Nowaddstufffrommemory
aFiles=objMemoryFiles.Keys

ForlTemp=0toUBound(aFiles)
objInStream.Open
objInStream.WriteTextobjMemoryFiles.Item(aFiles(lTemp))
objInStream.Position=0
ExportFileaFiles(lTemp),objStream,objInStream
objInStream.Close
Next
objStream.WriteTextString(BlockSize,Chr(0))
Rewindthestream
Remembertochangethetypebacktobinary,otherwisethewritewilltruncate
pastthefirstzerobytecharacter.
objStream.Position=0
objStream.Type=1
Setallthebrowserstuff
Response.AddHeader"Content-Disposition","filename="&TarFilename
Response.ContentType="application/x-tar"
Response.BinaryWriteobjStream.Read

Closeitandgohome
objStream.Close
SetobjStream=Nothing
SetobjInStream=Nothing
EndSub

Buildaheaderforeachfileandsendthefilecontents
PrivateSubExportFile(sFilename,objOutStream,objInStream)
DimlStart,lSum,lTemp

lStart=objOutStream.PositionRecordwhereweareupto

IfIgnorePathsThen
Weignoreanypathsprefixedtoourfilenames
lTemp=InStrRev(sFilename,"")
iflTemp0then
sFilename=Right(sFilename,Len(sFilename)-lTemp)
endif
sFilename=BasePath&sFilename
EndIf

Buildtheheader,everythingisASCIIinoctalexceptforthedata
objOutStream.WriteTextLeft(sFilename&String(100,Chr(0)),100)
objOutStream.WriteText"100"&Right("000"&Oct(Permissions),3)&""&Chr(0)Filemode
objOutStream.WriteTextRight(String(6,"")&CStr(UserID),6)&""&Chr(0)uid
objOutStream.WriteTextRight(String(6,"")&CStr(GroupID),6)&""&Chr(0)gid
objOutStream.WriteTextRight(String(11,"0")&Oct(objInStream.Size),11)&Chr(0)size
objOutStream.WriteTextRight(String(11,"0")&Oct(dateDiff("s","1/1/197010:00",now())),11)&Chr(0)mtime(Numberofsecondssince10amonthe1stJanuary1970(10amcorrect?)
objOutStream.WriteText"0"&String(100,Chr(0))chksum,typeflagandlinkname,writeoutallblankssothattheactualchecksumwillgetcalculatedcorrectly
objOutStream.WriteText"ustar"&Chr(0)magicandversion
objOutStream.WriteTextLeft(UserName&String(32,Chr(0)),32)uname
objOutStream.WriteTextLeft(GroupName&String(32,Chr(0)),32)gname
objOutStream.WriteText"40"&String(4,Chr(0))devmajor,devminor
objOutStream.WriteTextString(167,Chr(0))prefixandleader
objInStream.CopyToobjOutStreamSendthedatatothestream

if(objInStream.SizeModBlockSize)>0then
objOutStream.WriteTextString(BlockSize-(objInStream.SizeModBlockSize),Chr(0))Paddingtothenearestblockbyteboundary
endif

Calculatethechecksumfortheheader
lSum=0
objOutStream.Position=lStart

ForlTemp=1ToBlockSize
lSum=lSum+(Asc(objOutStream.ReadText(1))And&HFF&)
Next

Insertit
objOutStream.Position=lStart+148
objOutStream.WriteTextRight(String(7,"0")&Oct(lSum),7)&Chr(0)

Movetotheendofthestream
objOutStream.Position=objOutStream.Size
EndSub

Starteverythingoff
PrivateSubClass_Initialize()
SetobjFiles=Server.CreateObject("Scripting.Dictionary")
SetobjMemoryFiles=Server.CreateObject("Scripting.Dictionary")

BlockSize=512
Permissions=438UNIX666

UserID=0
UserName="root"
GroupID=0
GroupName="root"

IgnorePaths=False
BasePath=""

TarFilename="new.tar"
EndSub

PrivateSubClass_Terminate()
SetobjMemoryFiles=Nothing
SetobjFiles=Nothing
EndSub
EndClass
%>
ASP脚本是采用明文(plaintext)方式来编写的。
作者: 活着的死人    时间: 2015-1-18 22:01
掌握asp的特性而且一定要知道为什么。
作者: admin    时间: 2015-1-25 12:12
在平时的学习过程中要注意现学现用,注重运用,在掌握了一定的基础知识后,我们可以尝试做一些网页,也许在开始的时候我们可能会遇到很多问题,比如说如何很好的构建基本框架。
作者: 冷月葬花魂    时间: 2015-2-2 22:04
代码的可重用性差:由于是面向结构的编程方式,并且混合html,所以可能页面原型修改一点,整个程序都需要修改,更别提代码重用了。
作者: 爱飞    时间: 2015-2-8 11:24
先学习用frontpage熟悉html编辑然后学习asp和vbscript建议买书进行系统学习
作者: 第二个灵魂    时间: 2015-2-25 10:56
运用ASP可将VBscript、javascript等脚本语言嵌入到HTML中,便可快速完成网站的应用程序,无需编译,可在服务器端直接执行。容易编写,使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行。
作者: 兰色精灵    时间: 2015-3-7 20:27
Response:从字面上讲是“响应”,因此这个是服务端向客户端发送东西的,例如Response.Write
作者: 乐观    时间: 2015-3-15 14:02
作为IE上广为流传的动态网页开发技术,ASP以它简单易学博得了广大WEB程序爱好这的青睐,而且它对运行环境和开发品台的不挑剔,以及有大量有效的参考手册,极大的推广了它的发展。
作者: 仓酷云    时间: 2015-3-22 01:45
ASP.Net和ASP的最大区别在于编程思维的转换,而不仅仅在于功能的增强。ASP使用VBS/JS这样的脚本语言混合html来编程,而那些脚本语言属于弱类型、面向结构的编程语言,而非面向对象,这就明显产生以下几个问题:




欢迎光临 仓酷云 (http://ckuyun.com/) Powered by Discuz! X3.2