Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Inside

[Resolvido] Upload

Recommended Posts

Caros amigos,

 

necessito de uma ajuda. Tenho esse código de upload, funciona bem, mas agora preciso colocar o nome do arquivo postado, na tela. Já tentei fazer vários response.write com as variáveis do código mas não achei qual pega o nome do arquivo. Dá para fazer isso?

 

<%
select case request("acao")
case "enviar"

'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'' MULT UPLOAD
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

dim UploadQueryString, AF_uploadAction, AF_redirectPage, RequestBin, PosBeg, i, char, Posend, boundary, boundaryPos, Pos, intCount, Name, PosFile, PosBound, FileName, ContentType, Value, ValueBeg, ValueLen, Valueend, AF_keys, AF_i, AF_curKey, AF_value, AF_valueBeg, AF_valueLen, AF_curPath

sub BuildUploadRequest(RequestBin)
 PosBeg = 1
 Posend = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
 if Posend = 0 then
	Response.Write "<b>O arquivo não foi enviado com o componente: ENCTYPE=""multipart/form-data""</b>
"
	Response.Write "Por favor faça a correção dos atributos do formulário e tente novamente. <a href=""javascript:history.back(1)"">voltar</a>."
	Response.end
 end if
 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))
 	FileName = Mid(FileName,InStrRev(FileName,"\")+1)
 	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 = FileName
 	ValueBeg = PosBeg-1
 	ValueLen = 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))
 	ValueBeg = 0
 	Valueend = 0
	end if
	UploadControl.Add "Value" , Value	
	UploadControl.Add "ValueBeg" , ValueBeg
	UploadControl.Add "ValueLen" , ValueLen	
	UploadRequest.Add name, UploadControl	
	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

function UploadFormRequest(name)
 if UploadRequest.Item(name) then
	UploadFormRequest = UploadRequest.Item(name).Item("Value")
 end if 
end function

UploadQueryString = Replace(Request.QueryString,"AF_upload=true","")
if mid(UploadQueryString,1,1) = "&" then
	UploadQueryString = Mid(UploadQueryString,2)
end if

AF_uploadAction = CStr(Request.ServerVariables("URL")) & "?AF_upload=true"
if (Request.QueryString <> "") then 
 if UploadQueryString <> "" then
 AF_uploadAction = AF_uploadAction & "&" & UploadQueryString
 end if 
end if

if (CStr(Request.QueryString("AF_upload")) <> "") then
 AF_redirectPage = "extranet_upload.asp?acao=upload"
 if (AF_redirectPage = "") then
	AF_redirectPage = CStr(Request.ServerVariables("URL"))
 end if
	
 RequestBin = Request.BinaryRead(Request.TotalBytes)
 Dim UploadRequest
 Set UploadRequest = CreateObject("Scripting.Dictionary") 
 BuildUploadRequest RequestBin
 
 AF_keys = UploadRequest.Keys
 for AF_i = 0 to UploadRequest.Count - 1
	AF_curKey = AF_keys(AF_i)
	if UploadRequest.Item(AF_curKey).Item("FileName") <> "" then
 	AF_value = UploadRequest.Item(AF_curKey).Item("Value")
 	AF_valueBeg = UploadRequest.Item(AF_curKey).Item("ValueBeg")
 	AF_valueLen = UploadRequest.Item(AF_curKey).Item("ValueLen")

 	if AF_valueLen = 0 then
 	Response.Write "<b>Um erro ocorreu durante o envio do arquivo!</b>

"
 	Response.Write "Arquivo: " & Trim(AF_curPath) & UploadRequest.Item(AF_curKey).Item("FileName") & "
"
 	Response.Write "O arquivo não existe ou está vazio.
"
 	Response.Write "Por favor repita a operação. <a href=""javascript:history.back(1)"">voltar</a>."
 response.end
		end if
 	
 	Dim AF_strm1, AF_strm2
 	Set AF_strm1 = Server.CreateObject("ADODB.Stream")
 	Set AF_strm2 = Server.CreateObject("ADODB.Stream")
 	
 	AF_strm1.Open
 	AF_strm1.Type = 1 'Binary
 	AF_strm2.Open
 	AF_strm2.Type = 1 'Binary
 	
 	AF_strm1.Write RequestBin
 	AF_strm1.Position = AF_ValueBeg
 	AF_strm1.CopyTo AF_strm2,AF_ValueLen
	
 	AF_curPath = Request.ServerVariables("PATH_INFO")
 	AF_curPath = Trim(Mid(AF_curPath,1,InStrRev(AF_curPath,"/")) & "")
 	if Mid(AF_curPath,Len(AF_curPath),1) <> "/" then
 	AF_curPath = AF_curPath & "/"
 	end if 
 	AF_strm2.SaveToFile Trim(Server.mappath(AF_curPath))& "\docs\" & UploadRequest.Item(AF_curKey).Item("FileName"),2
 	if err then
 	Response.Write "<b>Um erro ocorreu durante o envio do arquivo!</b>

"
 	Response.Write "Arquivo: " & Trim(AF_curPath) & UploadRequest.Item(AF_curKey).Item("FileName") & "
"
 	Response.Write "O diretório especificado não existe ou não foi configurado a permissão de escrita para a pasta selecionada.
"
 	Response.Write "Por favor verifique as configurações e repita a operação. <a href=""javascript:history.back(1)"">voltar</a>."
 err.clear
 response.end
		end if
	end if
 next

 if (AF_redirectPage <> "") then
	if (InStr(1, AF_redirectPage, "?", vbTextCompare) = 0 And UploadQueryString <> "") then
 	AF_redirectPage = AF_redirectPage & "?" & UploadQueryString
	end if
	Call Response.Redirect(AF_redirectPage) 
 end if 
 
end if 
if UploadQueryString <> "" then
 UploadQueryString = UploadQueryString & "&AF_upload=true"
else 
 UploadQueryString = "AF_upload=true"
end if 

set af_strm1 = nothing
set af_strm2 = nothing

'Fim Multi Upload
%>


<table border="0" cellspacing="0" cellpadding="0">
<tr><td> 
<form name="enviar_arquivo" method="post" action="<%=AF_uploadAction%>" enctype="multipart/form-data" onSubmit="return valida_enviar()">
<p><input type="file" name="files" size="40"></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr><td width="280"></td><td><input type="submit" name="submit1" class="submit" value="Enviar Arquivo(s)"></td></tr></table>
</form>
</td></tr></table>

<script language="JavaScript"><!--
function valida_enviar(form)
{
	if(enviar_arquivo.files.value.length == 0)
	{
		alert("Selecione um arquivo para enviar.");
		enviar_arquivo.files.focus();
		return false;
	}
}

// -->
</script>

<script language="JavaScript">
//Coloca o foco inicial no campo usuario.
document.enviar_arquivo.files.focus();
</script>

<% end select %>

<%
select case request("acao")
case "upload" %>




Arquivo(s) publicado(s) com sucesso!



Arquivo:
<%
response.write AF_value
%>

<meta name="refresh" http-equiv="refresh" content="2;URL=upload.asp?acao=enviar">

<% end select %>

 

Obrigado pela atenção de todos.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.