Dim sServerDir sServerDir = Server.MapPath( ConfigUserFilesPath ) If ( Right( sServerDir, 1 ) > "\" ) Then sServerDir = sServerDir "\" End If
把它下面的這兩行
Dim oFSO Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" ) 用下面這一段代碼來替換
dim arrPath,strTmpPath,intRow strTmpPath = "" arrPath = Split(sServerDir, "\") Dim oFSO Set oFSO = Server.CreateObject( "Scripting.FileSystemObject" ) for intRow = 0 to Ubound(arrPath) strTmpPath = strTmpPath arrPath(intRow) "\" if oFSO.folderExists(strTmpPath)=false then oFSO.CreateFolder(strTmpPath) end if next 用這段代碼就可以生成你想要的文件夾了,在上傳的時候自動生成。
在剛才那一段代碼的下面緊接著就是 ' Get the uploaded file name. sFileName = oUploader.File( "NewFile" ).Name 看清楚了,這個就是文件名啦,我們來把它改掉,當然得有個生成文件名的函數才行,改成下面這樣
'//取得一個不重復的序號 Public Function GetNewID() dim ranNum dim dtNow randomize dtNow=Now() ranNum=int(90000*rnd)+10000 GetNewID=year(dtNow) right("0" month(dtNow),2) right("0" day(dtNow),2) right("0" hour(dtNow),2) right("0" minute(dtNow),2) right("0" second(dtNow),2) ranNum End Function
' Get the uploaded file name. sFileName = GetNewID() "." split(oUploader.File( "NewFile" ).Name,".")(1)