| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 865 人关注过本帖
标题:关于ASP无组件上传文件的命名问题
只看楼主 加入收藏
lostopen13
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-9-26
收藏
 问题点数:0 回复次数:3 
关于ASP无组件上传文件的命名问题
我想用ASP无组件上传文件,文件名不变;比如:我上传 5.jpg上传后还是5.jpg
请教怎么改

<%
dim Upload,File,FormName,SaveToPath,FileName,FileExt
dim RanNum
call UpFile()
'===========无组件上传(upload_0)====================
sub UpFile()
  set Upload=new UpFile_Class '建立上传对象
  Upload.GetData (1024*1024*15) '取得上传数据,此处即为15M

  if Upload.err > 0 then
    select case Upload.err
      case 1
        Response.Write "请先选择您要上传的文件,<a href=# onclick=history.go(-1)>返回</a>&nbsp;!"
      case 2
        Response.Write "文件大小超过了限制15M,<a href=# onclick=history.go(-1)>返回</a>&nbsp;!"
    end select
    exit sub
  else
    SaveToPath=Upload.form("SaveToPath") '文件保存目录,此目录必须为程序可读写
    if SaveToPath="" then
      SaveToPath="../"
    end if
    '在目录后加(/)
    if right(SaveToPath,1)<>"/" then
      SaveToPath=SaveToPath&"/"
    end if
    for each FormName in Upload.file '列出所有上传了的文件
      set file=Upload.file(FormName) '生成一个文件对象
      if file.Filesize<100 then
        response.write "请先选择您要上传的文件,<a href=# onclick=history.go(-1)>返回</a>&nbsp;!"
        response.end
      end if

      FileExt=lcase(File.FileExt)
      if CheckFileExt(FileEXT)=false then
        response.write "文件格式不允许上传,<a href=# onclick=history.go(-1)>返回</a>&nbsp;!"
        response.end
      end if

      randomize timer
      RanNum=int(9000*rnd)+1000
      Filename=SaveToPath&request("FileName")&fileExt
      if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
        Result=file.SaveToFile(Server.mappath(FileName)) '保存文件
        if Result="ok" then
        
          response.write "<table width='100%' border='0' cellspacing='0' cellpadding='0'>"
          response.write "<tr>"
          response.write "<td width='60' height='30'>上传成功:</td>"
          response.write "<td nowrap><font color='#ff0000'>"&File.FilePath&file.FileName&"</font></td>"
          response.write "</tr>"
          response.write "<tr>"
          response.write "<td nowrap height='30'>保存路径:</td>"
          response.write "<td nowrap><input type='text' size='56' class='textfield' value='"&right(FileName,len(FileName))&"'></td>"
          response.write "</tr>"
          response.write "<tr>"
          response.write "<td nowrap height='30'>文件大小:</td>"
          response.write "<td nowrap><input type='text' size='56' class='textfield' value='"&GainFileSize(file.Filesize)&"'></td>"
          response.write "</tr>"          
          response.write "<tr>"
          response.write "<td height='36' colspan='2' valign='bottom' align='center'><input name='CopyPath' type='button' class='button' value='拷贝文件路径'  onclick=""CopyPath('"&right(FileName,len(FileName))&"','"&GainFileSize(file.Filesize)&"')""></td>"
          response.write "</tr>"
          response.write "</table>"
        else
          response.write File.FilePath&file.FileName&"上传失败&nbsp;!"&Result&"<br>"
        end if
      end if
      set file=nothing
    next
    set Upload=nothing
  end if
end sub

'判断文件类型是否合格
Private Function CheckFileExt (FileEXT)
  dim ForumUpload
  ForumUpload="exe,gif,jpg,jpeg,rar,zip,doc"
  ForumUpload=split(ForumUpload,",")
  for i=0 to ubound(ForumUpload)
    if lcase(FileEXT)=lcase(trim(ForumUpload(i))) then
      CheckFileExt=true
      exit Function
    else
      CheckFileExt=false
    end if
  next
End Function

Private Function GainFileSize (SizeByte)
  if SizeByte < 1024*1024 then
    GainFileSize=round(SizeByte/1024,2) & "&nbsp;KB"
  else  
    GainFileSize=round(SizeByte/1024/1024,2) & "&nbsp;MB"
  end if
End Function

%>
搜索更多相关主题的帖子: 组件 ASP 文件 
2008-09-26 14:54
lostopen13
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-9-26
收藏
得分:0 
晕 看了不会贴啊
2008-09-26 15:28
lostopen13
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-9-26
收藏
得分:0 
没人知道吗 在线等啊 急死了
2008-09-26 16:53
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 
先说一下,这行代码是有语法错误的,不过编译器经常抽风不报错:
  Upload.GetData (1024*1024*15) '取得上传数据,此处即为15M

关于保存文件,我觉得关键在这里:
程序代码:
      Filename=SaveToPath&request("FileName")&fileExt
      if file.FileSize>0 then '如果 FileSize > 0 说明有文件数据
        Result=file.SaveToFile(Server.mappath(FileName)) '保存文件


用FileName确定了文件要保存到哪里,这里调用了一个Request("FileName"),估计是表单里的“文件标题”域,那么你要获取原文件名,这个建议你看一下Upload类里是怎么定义的。
2008-09-26 22:59
快速回复:关于ASP无组件上传文件的命名问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020725 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved