上传文件代码:upload.asp
调用的方法
<form method="POST" enctype="multipart/form-data" action="?act=upload">
<input type="file" size="20" name="file1"><input type="submit" value="上传">
</form>
<%
if request("act") = "upload" then
'****************************************
' 功能:aspUpload有组件上传文件
' 作者:wangsdong
' 网址:www.aspprogram.cn
' 原创源码,转载请保留此信息,谢谢
'****************************************
AllowExt = "swf,flv"
FileSize=1024*500
'On Error Resume Next
' 新建AspUpload对象
Set Upload = Server.CreateObject("Persits.Upload")
' 限制文件大小
Upload.SetMaxSize FileSize*1024, True
' 上传路径--当前目录下的uploadfile目录
path="uploadfile"
path=path&"/"&year(now)&"-"&month(now)
uploadDir = Server.MapPath(path)
AutoCreateFolder(uploadDir) '创建文件夹
' 尝试创建路径文件夹,true表示忽略目录已存在错误
'Upload.CreateDirectory uploadDir, true
' 先上传文件至服务器内存
Count = Upload.Save()
' 检测上传错误
If Err.Number = 8 Then
Response.Write chinese2unicode("错误: 文件过大!")
Response.end
Else
If Err <> 0 Then
response.write chinese2unicode("发生错误:")
response.write chinese2unicode(Err.Description)
response.end
End If
End If
'Response.Write chinese2unicode("共 " & Count & " 个文件") & "<br><br>"
' 指定一个上传的表单文件
Set File = Upload.Files("file1")
If Not File Is Nothing Then
' 获取原本文件名
'Filename = File.Filename '如果使用原文件名,请去掉前面的单引号
filename=replace(replace(replace(now()," ",""),"-",""),":","")&File.Ext '以时间为文件名
' 获取文件扩展名
Fileext = File.Ext
v=path&"/"&filename
' 检测文件格式是否合格
ChkStr = ","&Lcase(AllowExt)&","
If Instr(ChkStr,","&LCase(right(Fileext,3))&",") <= 0 Then
Response.Write chinese2unicode("错误: 文件类型不正确!")
response.write "<br>"
response.write chinese2unicode("只允许:"&AllowExt)
' 删除内存中的临时文件,以释放内存或硬盘空间(还可用Copy、Move两个指令)
File.Delete
' 检测是否存在文件
elseif Upload.FileExists(uploadDir & "\" & Filename) Then
File.SaveAs uploadDir & "\" & Filename
Response.Write chinese2unicode("已覆盖存在相同文件名的文件: ") & File.Path
' 保存文件
else
File.SaveAs uploadDir & "\" & Filename
'Response.Write chinese2unicode("文件已保存到: ") & File.Path
'v=Replace(UploadFilePath&file.filename,"../","")
response.write "<script>parent.form1.flash_path.value='"&v&"';window.close();</script>"
end If
Else
Response.Write chinese2unicode("错误: 您并没有选择文件!")
End If
end If
' gb2312转unicode,解决中文乱码问题
function chinese2unicode(Str)
dim i
dim Str_one
dim Str_unicode
for i=1 to len(Str)
Str_one=Mid(Str,i,1)
Str_unicode=Str_unicode&chr(38)
Str_unicode=Str_unicode&chr(35)
Str_unicode=Str_unicode&chr(120)
Str_unicode=Str_unicode& Hex(ascw(Str_one))
Str_unicode=Str_unicode&chr(59)
next
Response.Write Str_unicode
end function
'--------------------------------
'自动创建指定的多级文件夹
'strPath为绝对路径
Function AutoCreateFolder(strPath) 'As Boolean
On Error Resume Next
Dim astrPath, ulngPath, i, strTmpPath
Dim objFSO
If InStr(strPath, "\") <=0 or InStr(strPath, ":") <= 0 Then
AutoCreateFolder = False
Exit Function
End If
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strPath) Then
AutoCreateFolder = True
Exit Function
End If
astrPath = Split(strPath, "\")
ulngPath = UBound(astrPath)
strTmpPath = ""
For i = 0 To ulngPath
strTmpPath = strTmpPath & astrPath(i) & "\"
If Not objFSO.FolderExists(strTmpPath) Then
'创建
objFSO.CreateFolder(strTmpPath)
End If
Next
Set objFSO = Nothing
If Err = 0 Then
AutoCreateFolder = True
Else
AutoCreateFolder = False
End If
End Function
%>
调用的方法
<form name="form1" action="edit.asp?action=save" method="post" onSubmit="return checkInput();">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="12%" height="25" align="right">视频地址:</td>
<td width="88%"><input type="text" name="flash_path" size="30" maxlength="25"></td>
</tr>
<tr>
<td width="12%" height="25" align="right">上传视频:</td>
<td width="88%"><iframe src="../upload.asp" scrolling="no" topmargin="0" width="300" height="25" marginwidth="0" marginheight="0" frameborder="0"></iframe></td>
</tr>
</table>
</form>