先看代码,Uploader.Class.asp:
Private Function CheckOrCreatePath( ByVal path )
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Dim parts
parts = Split( path, "\" )
path = ""
For Each part in parts
path = path + part + "\"
If fs.FolderExists( path ) = False Then
fs.CreateFolder( path )
End If
Next
End Function
这个函数是根据路径自动创建多层次的目录,如:D:\WebSite\Demo\web\asp\upload\image\20150426\ 这个目录,创建的时候会一层一层的创建。
D:\WebSite\Demo\web 这个是我们的网站根目录,这个以上的目录,一般我们都没有读写的权限
这个函数创建目录如下:
D:\
D:\WebSite\
D:\WebSite\Demo\
D:\WebSite\Demo\web\
D:\WebSite\Demo\web\asp\
D:\WebSite\Demo\web\asp\upload\
D:\WebSite\Demo\web\asp\upload\image\
D:\WebSite\Demo\web\asp\upload\image\20150426\
创建的时候,没有权限访问到的目录
D:\
D:\WebSite\
D:\WebSite\Demo\
所以运行到这里就会出错了,但是没有任何错误消息返回。。
我把这个函数改了一下,但是感觉还不够完美,如下:
Private Function CheckOrCreatePath(ByVal path)
Set fs = Server.CreateObject("Scripting.FileSystemObject")
Dim parts
parts = Split( path, "\" )
path = ""
For Each part in parts
path = path + part + "\"
If fs.FolderExists( path ) = False and instr(path,split(rsFilePath,"/")(1))>0 Then
fs.CreateFolder( path )
End If
Next
End Function
也就是新添加了一个判断: and instr(path,split(rsFilePath,"/")(1))>0 这个判断是有局限性的。。
rsFilePath 是 从config.json 中读取来的 ,我的配置是这样的:
instr(path,split(rsFilePath,"/")(1))>0 判断是否包含 字符串 upload
通过加个这样的判断,就不会再访问上级没有权限的目录了。
还有就是,config_loader.asp 这个文件要保存成 utf-8 包含Unicode 签名(BOM)格式的。。。这个弄不明白是为啥。。但是保存成这个格式就可以上传,去掉签名,就出错。。