欢迎光临
我们一直在努力

很好的上传!无组件!文件上传!包含其他文本字段!文件自动更名!简单易用!

建站超值云服务器,限时71元/月

其中部分代码根据化境代码改编!!
upload.htm
<html>

<head>
<meta http-equiv="content-language" content="zh-cn">
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<meta name="generator" content="microsoft frontpage 4.0">
<meta name="progid" content="frontpage.editor.document">
<title>new page 1</title>
<link rel="stylesheet" href="../public/css.css">
</head>
<script language="javascript">
<!–
function checkform1()
  {

  if (form1.names.value=="")
    {
    alert("请输入名称!")
    form1.names.focus()
    return false
    }
  if (form1.pic.value=="")
    {
    alert("请选择图片!")
    form1.pic.focus()
    return false
    }
  return true
  }

//–>
</script>
<body>

<table border="0" width="100%">
<form name="form1" enctype="multipart/form-data" action="upload.asp" method="post" onsubmit="return checkform1()">
  <tr>
    <td width="100%" colspan="2">
      <p align="center"><b>上传示例</b></td>
  </tr>
  
  <tr>
    <td width="40%" align="right">名称:</td>
    <td width="60%"><input type="text" name="names" size="30" maxlength="20" class="input1"></td>
  </tr>
  <tr>
    <td width="40%" align="right">图样:</td>
    <td width="60%"><input type="file" name="pic" size="30" maxlength="20" class="input1"  onblur="document.all.picview.src=document.all.pic.value"></td>
  </tr>
  
  <tr>
    <td width="40%" align="right"> </td>
    <td width="60%"><input  type="submit" value="   o k   " class="inputbtn"></td>
  </tr>
  <tr>
    <td width="100%" align="center" colspan="2">
    图象预览(选择图片后,点击页面任意处即可进行预览)<br>
    <img id="picview" border="1">
    </td>
    
  </tr>
  </form>
</table>

</body>

</html>

—–upload.asp
<!–#include file="savefile.asp"–>
<%
set objstream = server.createobject("adodb.stream")
  
  objstream.mode=3
  objstream.type = 1
  objstream.open
  
  objstream.write request.binaryread(request.totalbytes)
  
  names= getvalue("names",true,"")
  
  pic=getvalue("pic",false,"upimg/")
  

objstream.close
response.write("names:"+names)
response.write ("文件已上传!("+pic+")")
%>

—–savefile.asp
<%
  dim stream1,stream2,istart,iend,filename
  istart=1
  vbenter=chr(13)&chr(10)

function getvalue(fstr,foro,paths)fstr为接收的名称,foro布尔false为文件上传,true 为普通字段,path为上传文件存放路径
  if foro then
    getvalue=""
    istart=instring(istart,fstr)

    istart=istart+len(fstr)+5
    iend=instring(istart,vbenter+"—————————–")
    if istart>5+len(fstr) then
    getvalue=substring(istart,iend-istart)
   
    else
    getvalue=""
    end if
    else
    istart=instring(istart,fstr)
    istart=istart+len(fstr)+13
    iend=instring(istart,vbenter)-1
    
    filename=substring(istart,iend-istart)
    filename=getfilename(filename)
  
    istart=instring(iend,vbenter+vbenter)+3
    iend=instring(istart,vbenter+"—————————–")
    filestart=istart
    filesize=iend-istart-1
    objstream.position=filestart
    set sf = server.createobject("adodb.stream")
    sf.mode=3
    sf.type=1
    sf.open
    objstream.copyto sf,filesize
    
    if filename<>"" then
    set rf = server.createobject("scripting.filesystemobject")
    i=0
    fn=filename
    while rf.fileexists(server.mappath(paths+fn))

      fn=cstr(i)+filename
      i=i+1
      wend
    filename=fn
    sf.savetofile server.mappath(paths+filename),2
    end if
    getvalue=filename
    end if
  
end function

private function getfilename(fullpath)
  if fullpath <> "" then
   getfilename = mid(fullpath,instrrev(fullpath, "\")+1)
  else
   getfilename = ""
  end if
end  function

function instring(thestart,varstr)
dim i,j,bt,thelen,str
instring=0
str=tobyte(varstr)
thelen=lenb(str)
for i=thestart to objstream.size-thelen
   if i>objstream.size then exit function
   
   objstream.position=i-1
   if ascb(objstream.read(1))=ascb(midb(str,1)) then
    instring=i
    for j=2 to thelen
      if objstream.eos then  
        instring=0
        exit for
      end if
      if ascb(objstream.read(1))<>ascb(midb(str,j,1)) then
        instring=0
        exit for
      end if
    next
    if instring<>0 then exit function
   end if
next
end function

function tobyte(str)
   dim i,icode,c,ilow,ihigh
   tobyte=""
   for i=1 to len(str)
   c=mid(str,i,1)
   icode =asc(c)
   if icode<0 then icode = icode + 65535
   if icode>255 then
     ilow = left(hex(asc(c)),2)
     ihigh =right(hex(asc(c)),2)
     tobyte = tobyte & chrb("&h"&ilow) & chrb("&h"&ihigh)
   else
     tobyte = tobyte & chrb(ascb(c))
   end if
   next
end function

function substring(thestart,thelen)
dim i,c,stemp
objstream.position=thestart-1
stemp=""
for i=1 to thelen
   if objstream.eos then exit for
   c=ascb(objstream.read(1))
   if c > 127 then
    if objstream.eos then exit for
    stemp=stemp&chr(ascw(chrb(ascb(objstream.read(1)))&chrb(c)))
    i=i+1
   else
    stemp=stemp&chr(c)
   end if
next
substring=stemp
end function
%>

呵呵!希望大家喜欢!

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 很好的上传!无组件!文件上传!包含其他文本字段!文件自动更名!简单易用!
分享到: 更多 (0)