主题:asp 怎么上传图片啊 还有文件
<%Server.ScriptTimeout = 6000%>
<!--#include FILE="uploadjs.inc"-->
<%Set dCN = CreateObject("Adodb.Connection")
dCN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("dinfo.mdb") & ";Persist Security Info=False"%>
<%
Dim objUpload,File,formName,iCount
UpFilePath = "photo/"
FileMaxSize = Session("uFileSize")*1024*1024
LostSize = Session("sLostSpace")
iCount = 0
Set objUpload = New upload_5xSoft
For Each formName In objUpload.objfile
Set File = objUpload.objfile(formName)
'If File.FileSize = 0 Then Exit For ' 没有文件数据时退出
'If File.FileSize >= LostSize Then ' 检查空间是否足够
' Response.write "<script>alert('你的文件夹剩下的空间不足放置上传的文件!');history.back();</script>"
' Set objUpload = Nothing
' Response.End
'End If
'If File.FileSize > FileMaxSize Then ' 文件大小超过最大限制
' Response.Write "<script>alert('文件大小超出限制,您最多可以上传 "& FileMaxSize\1024 &"KB的文件数据!');history.back();</script>"
' Set objUpload = Nothing
' Response.End
'End If
' 可加入根据文件名File.FileName后辍判断进行类型筛选
FileName = GetFileName(Session("username"), File.FileName)
File.SaveAs Server.mappath(UpFilePath & FileName)
'Response.Write File.FilePath & File.FileName & " (" & File.FileSize & ") 上传文件成功!<br>"
'Response.Write "你的文件路径是:" & UpFilePath & FileName & "<br>"
iCount = iCount+1
If objUpload.objForm("kid")="" Then
If objUpload.objForm("sname")="" Then objUpload.objForm("sname")=0
SQL="INSERT INTO tabPhone (姓名,照片,学历,资质,邮箱,特点,其他) VALUES ('" &_
objUpload.objForm("sname") & "','" & objUpload.objForm("sfile") & "','" & objupload.objform("sname1") & "','" & objUpload.objForm("snote") & "','" & objUpload.objForm("scolor") & "','" & objUpload.objForm("spay1") & "','" & objUpload.objForm("spay2") & "')"
CN.Execute SQL
Else
SQL="UPDATE tablayers SET 姓名='" & objUpload.objForm("sname") & "'," & _
"学历='" & objUpload.objForm("sname1") & "'," & _
"资质='" & objUpload.objForm("snote") & "'," & _
"邮箱=" & objUpload.objForm("scolor") & "," & _
"特点=" & objUpload.objForm("spay1") & "," & _
"其他=" & objUpload.objForm("spay2") & "," & _
" WHERE ID=" & objUpload.objForm("kid")
CN.Execute SQL
If sPhotoFile<>"" Then
SQL="UPDATE tablayers SET 照片='" & sFile & "' WHERE ID=" & objUpload.objForm("kid")
CN.Execute SQL
End If
end if
Set objUpload = Nothing
'If iCount > 0 Then
' Response.Write "<br>成功地上传了" & iCount & " 个文件!"
'Else
' Response.Write "<br>上传文件失败,请向管理员反应!"
' Response.Write "<br><br><br><center> [<a href=""javascript:history.back();""><<返回</a>]</center>"
'End If
Response.Redirect "config.asp"
'Response.End
%>
<%
Function GetFileName(sUser,sFile)
Dim sFileName
sFileName = sUser & sFile
sALL = Server.mappath("ufile/" & sFileName)
Set fso = server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(sALL) then
Pos = InstrRev(sFile,".")
sName = Left(sFile, Pos - 1)
sExt = Mid(sFile,Pos)
For i=1 to 100
sFileName = sUser & sName & i & sExt
sALL = Server.mappath("ufile/" & sFileName)
If fso.FileExists(sALL) then
'//
Else
GetFileName = sFileName
set fso = Nothing
Exit Function
End If
Next
GetFileName = sUser & sName & date & time & sExt
Else
GetFileName = sFileName
End If
set fso = Nothing
End Function
%>
急用 总是出错啊?Function GetFileName(sUser,sFile)
<!--#include FILE="uploadjs.inc"-->
<%Set dCN = CreateObject("Adodb.Connection")
dCN.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("dinfo.mdb") & ";Persist Security Info=False"%>
<%
Dim objUpload,File,formName,iCount
UpFilePath = "photo/"
FileMaxSize = Session("uFileSize")*1024*1024
LostSize = Session("sLostSpace")
iCount = 0
Set objUpload = New upload_5xSoft
For Each formName In objUpload.objfile
Set File = objUpload.objfile(formName)
'If File.FileSize = 0 Then Exit For ' 没有文件数据时退出
'If File.FileSize >= LostSize Then ' 检查空间是否足够
' Response.write "<script>alert('你的文件夹剩下的空间不足放置上传的文件!');history.back();</script>"
' Set objUpload = Nothing
' Response.End
'End If
'If File.FileSize > FileMaxSize Then ' 文件大小超过最大限制
' Response.Write "<script>alert('文件大小超出限制,您最多可以上传 "& FileMaxSize\1024 &"KB的文件数据!');history.back();</script>"
' Set objUpload = Nothing
' Response.End
'End If
' 可加入根据文件名File.FileName后辍判断进行类型筛选
FileName = GetFileName(Session("username"), File.FileName)
File.SaveAs Server.mappath(UpFilePath & FileName)
'Response.Write File.FilePath & File.FileName & " (" & File.FileSize & ") 上传文件成功!<br>"
'Response.Write "你的文件路径是:" & UpFilePath & FileName & "<br>"
iCount = iCount+1
If objUpload.objForm("kid")="" Then
If objUpload.objForm("sname")="" Then objUpload.objForm("sname")=0
SQL="INSERT INTO tabPhone (姓名,照片,学历,资质,邮箱,特点,其他) VALUES ('" &_
objUpload.objForm("sname") & "','" & objUpload.objForm("sfile") & "','" & objupload.objform("sname1") & "','" & objUpload.objForm("snote") & "','" & objUpload.objForm("scolor") & "','" & objUpload.objForm("spay1") & "','" & objUpload.objForm("spay2") & "')"
CN.Execute SQL
Else
SQL="UPDATE tablayers SET 姓名='" & objUpload.objForm("sname") & "'," & _
"学历='" & objUpload.objForm("sname1") & "'," & _
"资质='" & objUpload.objForm("snote") & "'," & _
"邮箱=" & objUpload.objForm("scolor") & "," & _
"特点=" & objUpload.objForm("spay1") & "," & _
"其他=" & objUpload.objForm("spay2") & "," & _
" WHERE ID=" & objUpload.objForm("kid")
CN.Execute SQL
If sPhotoFile<>"" Then
SQL="UPDATE tablayers SET 照片='" & sFile & "' WHERE ID=" & objUpload.objForm("kid")
CN.Execute SQL
End If
end if
Set objUpload = Nothing
'If iCount > 0 Then
' Response.Write "<br>成功地上传了" & iCount & " 个文件!"
'Else
' Response.Write "<br>上传文件失败,请向管理员反应!"
' Response.Write "<br><br><br><center> [<a href=""javascript:history.back();""><<返回</a>]</center>"
'End If
Response.Redirect "config.asp"
'Response.End
%>
<%
Function GetFileName(sUser,sFile)
Dim sFileName
sFileName = sUser & sFile
sALL = Server.mappath("ufile/" & sFileName)
Set fso = server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(sALL) then
Pos = InstrRev(sFile,".")
sName = Left(sFile, Pos - 1)
sExt = Mid(sFile,Pos)
For i=1 to 100
sFileName = sUser & sName & i & sExt
sALL = Server.mappath("ufile/" & sFileName)
If fso.FileExists(sALL) then
'//
Else
GetFileName = sFileName
set fso = Nothing
Exit Function
End If
Next
GetFileName = sUser & sName & date & time & sExt
Else
GetFileName = sFileName
End If
set fso = Nothing
End Function
%>
急用 总是出错啊?Function GetFileName(sUser,sFile)