asp createTextFile生成文本文件支持utf8(asscii)这都可以?

随心笔谈1年前 (2023)发布 admin
112 0


Function createTextFile(Byval content,Byval fileDir,Byval code)
dim fileobj,fileCode : fileDir=replace(fileDir, “”, “/”)
if isNul(code) then fileCode=Charset else fileCode=code
call createfolder(fileDir,”filedir”)
if fileCode=”utf-8″ then
on error resume next
With objStream
.Charset=fileCode:
.Type=2:
.Mode=3:
.Open:
.Position=0
.WriteText content:
.SaveToFile Server.MapPath(fileDir), 2
.Close
End With
else
on error resume next:err.clear
set fileobj=objFso.CreateTextFile(server.mappath(fileDir),True)
fileobj.Write(content)
set fileobj=nothing
end if
if Err Then err.clear :createTextFile=false : errid=err.number:errdes=err.description:Err.Clear : echoErr err_09,errid,errdes else createTextFile=true
End Function
Sub echoErr(byval str,byval id, byval des)

dim errstr,cssstr
cssstr=”<meta http-equiv=””Content-Type”” content=””text/html; charset=”&Charset&””” />”
cssstr=cssstr&”<style>body{text-align:center}#msg{background-color:white;border:1px solid #0073B0;margin:0 auto;width:400px;text-align:left}.msgtitle{padding:3px 3px;color:white;font-weight:700;line-height:28px;height30px;font-size:12px;border-bottom:1px solid #0073B0; text-indent:3px; background-color:#0073B0}#msgbody{font-size:12px;padding:20px 8px 30px;line-height:25px}#msgbottom{text-align:center;height:20px;line-height:20px;font-size:12px;background-color:#0073B0;color:#FFFFFF}</style>”
errstr=cssstr&”<script language=””javascript””>setTimeout(“”goLastPage()””,5000);function goLastPage(){location.href=’https://www.jb51.net/article/”& sitePath &”/’;}</script><div id=’msg’><div class=’msgtitle’>提示:【”&str&”】</div><div id=’msgbody’>错误号:”&id&”<br>错误描述:”&des&”<br /><a href=”https://www.jb51.net/article/”javascript:history.go(-1);” rel=”external nofollow” “>返回上一页</a> <a href=”https://www.jb51.net/article/”” rel=”external nofollow” & sitePath &”/””>返回首页</a></div><div id=’msgbottom’>Powered by AspCms2.0</div></div>”
cssstr=””
die(errstr)
End Sub
Function createFolder(Byval dir,Byval dirType)
dim subPathArray,lenSubPathArray, pathDeep, i
on error resume next
dir=replace(dir, “”, “/”)
if trim(sitePath)=”” then pathDeep=”/” else pathDeep=sitePath
pathDeep=server.MapPath(pathDeep)
dir=replace(server.mappath(dir), pathDeep, “”)
subPathArray=split(dir, “”)
select case dirType
case “filedir”
lenSubPathArray=ubound(subPathArray) – 1
case “folderdir”
lenSubPathArray=ubound(subPathArray)
end select
for i=0 to lenSubPathArray
if trim(subPathArray(i)) <> “” then
pathDeep=pathDeep&””&subPathArray(i)
if not objFso.FolderExists(pathDeep) then objFso.CreateFolder pathDeep
end if
next
if Err Then createFolder=false : errid=err.number:errdes=err.description:Err.Clear : echoErr err_10,errid,errdes else createFolder=true
End Function

© 版权声明

相关文章