当前位置: 移动技术网 > IT编程>开发语言>Asp > asp制作中常用到的函数库集合第1/8页

asp制作中常用到的函数库集合第1/8页

2017年12月12日  | 移动技术网IT编程  | 我要评论

 '************************************************** 
  '函数id:0011[指定目录的目录列表] 
  '函数名:listdirs 
  '作 用:指定目录的目录列表 
  '参 数:dirname ---- 目录名(包括路径) 
  '返回值:目录列表字符串,之间用“|”相隔 
  '************************************************** 
  public function listdirs(byval dirname) 
   dim m_fso,fns,fls,fnames,fnamesn 
   set m_fso = createobject("scripting.filesystemobject") 
   if (m_fso.folderexists(dirname)) then 
   set fns = m_fso.getfolder(dirname) 
   set fls=fns.subfolders 
   for each fnamesn in fls 
   fnames=fnames & fnamesn.name 
   fnames=fnames & "|" 
   next 
   listdirs=fnames 
   end if 
   set m_fso = nothing 
  end function 
  '************************************************** 
  '函数id:0012[创建文本文件] 
  '函数名:writtextfile 
  '作 用:创建文本文件 
  '参 数:fname ---- 文本文件名称(包括路径) 
  '参 数:writstring ---- 写入的内容 
  '返回值:创建成功返回true,否则false 
  '************************************************** 
  public function writtextfile(byval fname,byval writstring) 
   dim m_fso,fnamen 
   writtextfile=false 
   set m_fso = createobject("scripting.filesystemobject") 
   set fnamen= m_fso.opentextfile(fname,2,true) 
   fnamen.write writstring 
   fnamen.close 
   set m_fso = nothing 
   writtextfile=true 
  end function 
  '************************************************** 
  '函数id:0013[读取文本文件] 
  '函数名:readtextfile 
  '作 用:读取文本文件 
  '参 数:fname ---- 文本文件名称(包括路径) 
  '返回值:返回读取的文本内容 
  '************************************************** 
  public function readtextfile(byval fname) 
   dim m_fso,fnamen,fnr 
   readtextfile="" 
   set m_fso = createobject("scripting.filesystemobject") 
   set fnamen= m_fso.opentextfile(fname,1,true) 
   fnr=fnamen.readall 
   fnamen.close 
   set m_fso = nothing 
   readtextfile=fnr 
  end function 
  '************************************************** 
  '函数id:0014[检测id是否为数字类型] 
  '函数名:jcid 
  '作 用:检测id是否为数字类型 
  '参 数:paravalue ---- 被检测的id值 
  '返回值:返回id值,如果不为数字类型返回0 
  '************************************************** 
  public function jcid(byval paravalue) 
   if ((not isnumeric(paravalue)) or (trim(paravalue)="")) then 
   jcid=0 
   else 
   jcid=paravalue 
   end if 
  end function 
  '************************************************** 
  '函数id:0015[正则表达式测试] 
  '函数名:checkexp 
  '作 用:正则表达式测试 
  '参 数:patrn ---- 正则表达式 
  '参 数:strng ---- 要测试的字符串 
  '返回值:测试如果成立返回 true 否则 false 
  '例 checkexp("(\<.[^\<]*\>)","<br>") 
  '************************************************** 
  public function checkexp(byval patrn, byval strng) 
   dim regex, retval 
   set regex = new regexp 
   regex.pattern = patrn 
   regex.ignorecase = false 
   retval = regex.test(strng) 
   checkexp = retval 
  end function 
  '************************************************** 
  '函数id:0016[获得执行程序的名称] 
  '函数名:gt_the_proname 
  '作 用:获得执行程序的名称 
  '参 数: 
  '返回值:返回执行程序的名称 
  '************************************************** 
  public function gt_the_proname() 
   dim fu_name,temp,tempsiz 
   temp=request.servervariables("path_info") 
   fu_name=split(temp, "/", -1, 1) 
   tempsiz=ubound(fu_name) 
   gt_the_proname=fu_name(tempsiz) 
  end function 
  '************************************************** 
  '函数id:0017[读取用户ip地址信息] 
  '函数名:readusip 
  '作 用:读取用户ip地址信息 
  '参 数: 
  '返回值:返回用户ip地址 
  '************************************************** 
  public function readusip() 
   dim stripaddr 
   if request.servervariables("http_x_forwarded_for") = "" or instr(request.servervariables("http_x_forwarded_for"), "unknown") > 0 then 
   stripaddr = request.servervariables("remote_addr") 
   elseif instr(request.servervariables("http_x_forwarded_for"), ",") > 0 then 
   stripaddr = mid(request.servervariables("http_x_forwarded_for"), 1, instr(request.servervariables("http_x_forwarded_for"), ",")-1) 
   elseif instr(request.servervariables("http_x_forwarded_for"), ";") > 0 then 
   stripaddr = mid(request.servervariables("http_x_forwarded_for"), 1, instr(request.servervariables("http_x_forwarded_for"), ";")-1) 
   else 
   stripaddr = request.servervariables("http_x_forwarded_for") 
   end if 
   readusip = trim(mid(stripaddr, 1, 30)) 
  end function 
  '************************************************** 
  '函数id:0018[无组件上传文件到指定目录并改文件名称] 
  '函数名:upfsrn 
  '作 用:无组件上传文件到指定目录并更改文件名称 
  '参 数:retsize--- 上传限止大小(单位是m) 
  '参 数:fdir ---- 目标路径 
  '参 数:objwj ---- 目标文件名称 
  '返回值:如果成功 true 否则 false 
  '例 upfsrn(10,readsyspath(1)&"zfkhauto","test.txt") 
  '使用表单提取文件 <form method='post' action='function.asp' enctype='multipart/form-data'><input type='file' name='t1'><input type='submit' value='提交' name='b1'></form> 
  '************************************************** 
  public function upfsrn(byval retsize,byval fdir,byval objwj) 
   upfsrn=false 
   dim oupstream,ostream,formsize,formdata,strfilename,strfiledir,objallpath,datastart,dataend 
   strfiledir = fdir 
   strfilename = swj 
   objallpath = "" 
   if right(strfiledir,1)<>"\" then strfiledir=strfiledir&"\" 
   objallpath =strfiledir&objwj 
   if checkfile(objallpath) then delfile(objallpath) 
   formsize=request.totalbytes 
   if (formsize<=(retsize*1024*1024)) then 
   formdata=request.binaryread(formsize) 
   pos_ts=lenb(getbytestring(chr(13) & chr(10) & chr(13) & chr(10))) 
   pos_b=instrb(formdata,getbytestring(chr(13) & chr(10) & chr(13) & chr(10)))+pos_ts 
   nformdata=midb(formdata,pos_b) 
   pos_ts=instrb(nformdata,getbytestring(chr(13) & chr(10) & "--")) 
   nnformdata=midb(nformdata,pos_ts) 
   pos_e=lenb(formdata)-lenb(nnformdata)-pos_b+1 
   datastart =pos_b 
   dataend=pos_e 
   set oupstream = server.createobject("adodb.stream") 
   oupstream.type = 1 
   oupstream.mode = 3 
   oupstream.open 
   set ostream = server.createobject("adodb.stream") 
   ostream.type = 1 
   ostream.mode = 3 
   ostream.open 
   oupstream.write formdata 
   oupstream.position=datastart-1 
   oupstream.copyto ostream,dataend 
   ostream.savetofile objallpath,2 
   ostream.close 
   set ostream=nothing 
   upfsrn=true 
   end if 
  end function 
  '************************************************** 
  '函数id:0019[过滤html脚本] 
  '函数名:filterjs 
  '作 用:过滤html脚本 
  '参 数:strhtml ---- 被检测的html字串 
  '返回值:返回过滤后的html 
  '************************************************** 
  function filterjs(byval strhtml) 
   dim objreg,strcontent 
   if isnull(strhtml) or strhtml="" then exit function 
   set objreg=new regexp 
   objreg.ignorecase =true 
   objreg.global=true 
   objreg.pattern="(&#)" 
   strcontent=objreg.replace(strhtml,"") 
   objreg.pattern="(function|meta|value|window\.|script|js:|about:|file:|document\.|vbs:|frame|cookie)" 
   strcontent=objreg.replace(strcontent,"") 
   objreg.pattern="(on(finish|mouse|exit=|error|click|key|load|focus|blur))" 
   strcontent=objreg.replace(strcontent,"") 
   filterjs=strcontent 
   strcontent="" 
   set objreg=nothing 
  end function 
3

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网