<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%dbdns="../"%>
<!--#include file="../inc/Config.asp"-->
<!--#include file="../inc/err.asp"-->
<!--#include file="cook.asp"-->
<%if userflag23=0 then
response.redirect"ok.asp?action=flag"
end if
''主程序开始部分

dim formsize,formdata,Msg
formsize = Request.TotalBytes
formdata = Request.BinaryRead(formsize)
UploadSize=true

If Formsize = 0 or Formsize > OKsizePic Then
UploadSize=false
Response.Write "<script>alert('你要上传的单个文件大小超出系统限制,请返回修改重试');history.go(-1);</Script>"
Response.End
End If


dim sinfo_Stream
set Sinfo_Stream = Server.CreateObject("adodb.stream")
Sinfo_Stream.Type = 1		''2进制流
Sinfo_Stream.Mode = 3		''读写模式
Sinfo_Stream.Open
Sinfo_Stream.Write formdata		''保存二进制内容到流对象
''分离数据变量
dim VbEnter
dim spStr,lenOfspStr,bpos
dim loopcnt,exitflag,ppoint,npoint
''保存数据变量		
dim FldData,fldHeadStr,infldpos
dim databpos,datalen
dim FldInfo(15,1)
''fldInfo(0)表单头内容
''fldInfo(1)表单数据

VbEnter = chrb(13)&chrb(10)''读取第一个VbEnter位置
bpos = Instrb(formdata,VbEnter)
SpStr = midb(formdata,1,bpos+1) ''包含了一个0d0a
LenOfspStr = lenb(Spstr) 
ppoint = LenOfspStr+1 ''位置指针,指向每一个表单域内容的开始位置
formdata = midb(formdata,ppoint)
loopcnt = 0   ''表单元素
do 
	bpos = instrb(formdata,spStr) ''分割位置
	npoint = (ppoint+bpos+lenofspstr-1)  ''指向下一表单开始位置
	if bpos < 1 then
		fldData = midb(formdata,1,instrb(formdata,leftb(spStr,lenOfspstr-2))-1)
		bpos = lenb(fldData)+1
		exitflag = true
	else
		FldData = leftb(formdata,bpos-1)		
		formdata = midb(formdata,bpos+LenOfspstr)
	end if
	infldpos = instrb(fldData,vbEnter&vbEnter)
	fldHeadStr = bytes2bstr(midb(fldData,1,infldpos-1))
	fldInfo(loopcnt,0) = fldHeadStr	''表单头
	''Response.Write fldHeadStr&"<br>"
	databpos = (ppoint+infldpos-1+4)
	Sinfo_Stream.Position = databpos-1
	datalen = (bpos-infldpos-6)
	if datalen = 0 then
		fldInfo(loopcnt,1) = ""
	else
		fldInfo(loopcnt,1) = Sinfo_Stream.Read(datalen)
	end if
	ppoint = npoint
	loopcnt = loopcnt + 1
loop until exitflag = true
Sinfo_Stream.close
set Sinfo_Stream = Nothing


''以上程序数据处理过程
''写入数据库并处理文件上传开始
Sub SaveData()

dlxf_sort=myrequest("dlxf_sort")
dlxf_filename=myrequest("dlxf_filename")
yysize=myrequest("yysize")
if dlxf_sort="" or dlxf_filename="" or yysize="" then
response.write "<script>alert('对不起，请填写完整内容！');history.go(-1);</Script>"
Response.End 
end if

		filedata = myrequest("filedata")
		filesize = lenb(filedata)
		if  filesize > 0 then 
			filename = GetFileName("filedata")
			FileTypeName = GetFileTypeName(FileName)
		    If  IsvalidFile(FileTypeName)=false Then
			Response.Write "<script>alert('文件类型非法，不允许上传"&FileTypeName&"文件！');history.go(-1);</Script>"
			Response.End
		    Exit Sub
		    End If
'===================================================
yysize=yysize+filesize
if userflag7<round(yysize/1024,2) then
Response.Write "<script>alert('对不起，你的剩余空间已不足上传此文件，请修改重试！');history.go(-1);</Script>"
Response.End
end if
'===================================================路径
path=server.mappath(Request.ServerVariables("SCRIPT_NAME"))
basepath=left(left(path,instrRev(path,"\")),len(left(path,instrRev(path,"\")))-6)&"\UserDocument\"&session("useradmin")&"\Picture\"

set fso =server.CreateObject("Scripting.FileSystemObject")
If Fso.folderExists(server.mappath("../UserDocument"))=false Then
Fso.Createfolder(server.mappath("../UserDocument"))
end if
If Fso.folderExists(server.mappath("../UserDocument/"&session("useradmin")&""))=false Then
Fso.Createfolder(server.mappath("../UserDocument/"&session("useradmin")&""))
end if
If Fso.folderExists(server.mappath("../UserDocument/"&session("useradmin")&"/Picture"))=false Then
Fso.Createfolder(server.mappath("../UserDocument/"&session("useradmin")&"/Picture"))
end if
set fso =nothing
'===================================================
dim Fstream
set FStream = Server.CreateObject("adodb.stream")
fstream.mode = 3
fstream.type = 1
fstream.open
fstream.position = 0
fstream.Write filedata

filename=year(Now()) & right("0" & month(Now()),2) & right("0" & day(Now()),2) & right("0" & hour(Now()),2) & right("0" & minute(Now()),2) & right("0" & second(Now()),2)
nohack=split(filename&"."&FileTypeName,".")
tmpPath=basepath&nohack(0)&"."&nohack(ubound(nohack))

fstream.savetofile tmpPath
fstream.close
set fstream = nothing
'============================
		else
			Response.Write "<script>alert('请选择您要上传的文件！');history.go(-1);</Script>"
			Response.End
		end if
'===================================================
set rs=server.createobject("ADODB.Recordset")
sql="select * from dlxf_upfile"
rs.open sql,myconn,1,3
rs.addnew
rs("dlxf_yp_id")=session("id")
rs("dlxf_filename")=dlxf_filename
rs("dlxf_filesize")=filesize
rs("dlxf_fileadd")="UserDocument/"&session("useradmin")&"/Picture/"&filename&"."&FileTypeName
rs("dlxf_sort")=dlxf_sort
rs.update
rs.close
set rs=nothing
myconn.close
set myconn = nothing
'===================================================

End Sub	
SaveData
response.redirect"ok.asp?url=my_Picture.asp"
%>