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

随心笔谈2年前发布 编辑
161 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

© 版权声明

相关文章