酷!學園
技術討論區 => 網頁技術 => 主題作者是: b7307024 於 2020-07-22 14:34
-
各位前輩好,日前有其他網友建議可以使用Global.asa的Session_OnStart及Session_OnEnd來處理匯出時建立使用者資料夾,登出後刪除使用者資料夾的動作,來完成我的目的。
目前我的狀況如下:
login.asp
session.timeout=1440
session("EMPLOYEECODE")=rs("EMPLOYEECODE")
Global.asa
<script language="vbscript" runat="server">
Sub Application_OnStart
Application("Fdr") = Server.MapPath("\export\")
End Sub
Sub Session_OnStart
Application("Fdr") = Application("Fdr") & "\" & session("EMPLOYEECODE")
Set fs = CreateObject("Scripting.FileSystemObject")
If Not fs.FolderExists(Application("Fdr")) Then
fs.CreateFolder (Application("Fdr"))
End If
End Sub
</script>
這樣並不會成功建立使用者工號的資料夾,但若是使用
Application("Fdr") = Application("Fdr") & "\test"
則會成功建立test資料夾,請問該如何在登入後可以建立使用者資料夾呢?
謝謝!
-
後來我改為登入的時候建立使用者暫存資料夾
login.asp
Fdr = "\export\"&Session("EMPLOYEECODE")&""
If DeleteFolder(Fdr) = False Then
CreateFolder(Fdr)
Else
CreateFolder(Fdr) '預防使用者關閉瀏覽器,導致暫存資料夾沒有正常被刪除,故先刪除舊資料,在建立新資料夾
End If
然後登出logout.asp 或者 Session.Timeout 時,觸發Session_OnEnd刪除此資料夾
Global.asa
<script language="vbscript" runat="server">
Sub Application_OnStart
Application("Fdr") = Server.MapPath("\export\")
End Sub
Sub Session_OnEnd
Application.Lock
Fdr = Application("Fdr")& "\" & session("EMPLOYEECODE")
Application.UnLock
'刪除使用者暫存資料夾
Set Fso = Server.CreateObject("Scripting.FileSystemObject" )
If Fso.FolderExists(Fdr) Then '若資料夾存在,則刪除資料夾
Fso.Deletefolder Fdr,true
End If
Set Fso = Nothing
End Sub
</script>
這樣就完成我要的功能了,謝謝各位前輩!