<html>
<META NAME="Author" CONTENT="Wellington Marinheiro">
<body>
<script Language="JavaScript">
function ValidaPagina(form)
{
if(form.arq.value=="")
{
alert("Selecionar arquivo.");
form.arq.focus();
return false;
}
return true;
}
</script>
<%
If request.queryString("sid") = "" then
%>
<FORM METHOD="Post" ENCTYPE="multipart/form-data" ACTION="txt.asp?sid=1" onsubmit="return ValidaPagina(this);" name="envarq">
<table width="50%" border="0" align="CENTER" bgcolor="#EFEFEF" class=t2>
<tr bgcolor="#CCCCCC">
<th colspan="2">Lendo arquivo TXT</th>
</tr>
<tr>
<td><b>Localizar: </b></td>
<td height="42"><input type="file" name="arq" size="35"></td>
<tr>
<td colspan="2" align=center>
<input type="submit" value="Enviar" name="enviar" >
</td>
</tr>
</table>
</FORM>
<%
Else
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
filepathname = UploadRequest.Item("arq").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
ext =split(filename,".")
If ext(1) <> "txt" Then
response.write "<center><div>Selecione um arquivo com extensão TXT"
response.write "<BR><input type='button' value='<--- Voltar' name='bot' onClick='javascript:history.go(-1)'>"
response.write "</div></center>"
response.End
End if
response.write "<input type='button' value='Ler novo arquivo' name='bot3' onClick='javascript:history.go(-1)'>"
response.write "<HR>Local/Nome do Arquivo: " & filepathname & "<br><BR>Conteúdo:<HR>"
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile(filepathname, 1)
do while f.AtEndOfStream = false
Response.Write(f.ReadLine) & "<br>"
loop
f.Close
Set f=Nothing
Set fs=Nothing
End if
Sub BuildUploadRequest(RequestBin)
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
If PosFile<>0 AND (PosFile<PosBound) Then
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
UploadControl.Add "Value" , Value
UploadRequest.Add name, UploadControl
'Loop
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
%>