Ir para conteúdo

POWERED BY:

Arquivado

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

Eduardo Villa

[Resolvido] Sistema de Upload (adptar para multiplos UPLOADS)

Recommended Posts

Olá Galera...

 

Estou com um sistema de UPLOAD funcionando certinho, mas agora o meu cliente quer que ele faça 3 upload... tanto os 3 juntos como os 3 separados (coisa de cliente kkkk)

Vou postar o código , para ver se tem como adaptar o mesmo.

 

upload_funcoes.asp

<% if session("usr_log_ok") = 1 then
response.write ""
else
response.redirect "../default.asp"
end if
%>
<%
' Upload Sem componentes ---------------------------------------
Sub BuildUploadRequest(RequestBin)
on error resume next

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
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

' Fim upload sem Componentes -----------------------------------------
%>

upload_form.asp

<% if session("usr_log_ok") = 1 then
response.write ""
else
response.redirect "../default.asp"
end if
%>
<!-- #include file = "upload_funcoes.asp" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
@import url("../geral-index.css");
@import url("../estilo-news.css");
</style>
<!--[if IE]>
	<style type="text/css">
	#menu{
		width: 947px;
		height: 25px;
		font-family: "arial black";
		font-size: 8pt;
		margin-top: 0px;
		margin-left: 0px;
		background-image: url(images/fundo_menu.png);
		text-align: left;
		
	}
	#menu ul{
		width: 945px;
		margin-top: 5px;
		float: left;
		list-style: none;
		margin-left: -12px;		
	}
	#menu ul li{
		display: inline;
		margin-left: -10px;
		padding-left: 50px;
	}
	#menu ul li a{
		color: #2B6377;
		text-decoration: none;
	}
	#menu ul li a:hover{
		color: #FFF;
	}
</style>
<![endif]-->
<script src="../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>


</head>
<body>
<div id="wrapper">
  <div id="topo">
	<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','948','height','243','accesskey','948','tabindex','243','src','../topo_teste','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../topo_teste' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="948" height="243" accesskey="948" tabindex="243">
	  <param name="movie" value="../topo_teste.swf" />
	  <param name="quality" value="high" />
	  <embed src="../topo_teste.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="948" height="243"></embed>
	</object></noscript>
  </div>  <!-- Termina topo !-->
  <div id="conteudo" style="padding-top:10px;">
  <span class="noticia1">
  <input name="imagem2" type="file" class="noticia" size="50" />
  </span>
  <table width="779" border="0" align="center">
<form name="form1" action="upload_form2.asp" method="post" enctype="multipart/form-data">
<tr>
  <td colspan="2"><span class="titulo">Register Promotions</span></td>
  </tr>
<tr>
  <td width="225" class="inform"><a href="../lista_upimagem.asp">Back</a></td>
  <td> </td>
</tr>
<tr>
  <td colspan="2"align="center" class="inform">Please provide details of the promotions. All fields are   typing required.</td>
  </tr>
<tr>
<td class="form" align="right">Title:</td>
<td width="544"><input name="titulo" type="text" class="noticia" size="60"></td>
</tr>
<tr>
  <td align="right" class="form">Text:</td>
  <td rowspan="2"><textarea name="noticia" cols="80" rows="10" wrap="virtual" class="noticia"></textarea></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
  <td align="right" class="form">Image1:</td>
  <td class="noticia1"><input name="imagem" type="file" class="noticia" size="50">
  Tamanho: 200x250(px)</td>
</tr>
<tr>
<td colspan="2" align="center">
	<input name="btn_cad_imagem" type="submit" class="leiamais" value="Register"></td>
</tr>
</form> 
</table>
  </div> <!-- Termina weather !-->	
  <div id="rodape">	
  </div> <!-- Termina rodape !-->  
</div> <!-- Termina conteudo !-->
</div> <!-- Termina wrapper !-->

</body>
</html>

upload_form2.asp

<% if session("usr_log_ok") = 1 then
response.write ""
else
response.redirect "../default.asp"
end if
%>
<!-- #include file = "upload_funcoes.asp" -->
<html>  
<head>
<style type="text/css">
@import url("../geral-index.css");
</style>
<script src="../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>

<link href="../estilo-news.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
  <div id="topo">
	<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','948','height','243','accesskey','948','tabindex','243','src','../topo_teste','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../topo_teste' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="948" height="243" accesskey="948" tabindex="243">
	  <param name="movie" value="../topo_teste.swf" />
	  <param name="quality" value="high" />
	  <embed src="../topo_teste.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="948" height="243"></embed>
	</object></noscript>
  </div>  <!-- Termina topo !-->
  <div id="conteudo" style="padding-top:10px;">
<%
' Chamando Funções, que fazem o Upload funcionar
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin

' Recuperando os Dados Digitados ----------------------
titulo = UploadRequest.Item("titulo").Item("Value")
noticia = UploadRequest.Item("noticia").Item("Value")

' Tipo de arquivo que esta sendo enviado
tipo_foto = UploadRequest.Item("imagem").Item("ContentType")

' Caminho completo dos arquivos enviados
caminho_foto = UploadRequest.Item("imagem").Item("FileName")

' Nome dos arquivos enviados
nome_foto = Right(caminho_foto,Len(caminho_foto)-InstrRev(caminho_foto,"\"))

' Conteudo binario dos arquivos enviados
foto = UploadRequest.Item("imagem").Item("Value")

' pasta onde as imagens serao guardadas
pasta = Server.MapPath("imagens/")
nome_foto = "/"&nome_foto

' pasta + nome dos arquivos
cfoto = "imagens" + nome_foto

' Fazendo o Upload do arquivo selecionado
if foto <> "" then
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set MyFile = ScriptObject.CreateTextFile(pasta & nome_foto)
For i = 1 to LenB(foto)
MyFile.Write chr(AscB(MidB(foto,i,1)))
Next
MyFile.Close
end if

' Conecta-se ao Banco de Dados
url_conexao = Server.MapPath("*******************")
set conexao = Server.CreateObject("ADODB.Connection")
conexao.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="&url_conexao 

' cadastra os dados no banco de dados
sql = "Insert into promotions (titulo, noticia, imagem) values ('"& titulo &"', '"& noticia &"', '"& cfoto &"')"
Conexao.Execute(sql)

response.write "<meta http-equiv='refresh' content='5; url=../lista_upimagem.asp'/>"
%>
<br />
<br />
		 <table width="639" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
				<td align="center" class="form">Dados Cadastrados com Sucesso!</td>
			  </tr>
			  <tr>
				<td align="center" class="form">Você será redirecionado em 5 segundos..</td>
			  </tr>
	  </table>
		 <br />
		 <br />
  </div> <!-- Termina weather !-->	
  <div id="rodape">	
  </div> <!-- Termina rodape !-->  
</div> <!-- Termina conteudo !-->
</div> <!-- Termina wrapper !-->

</body>
</html>

Valew pela ajuda e aguardo resposta

Dudesigner

Compartilhar este post


Link para o post
Compartilhar em outros sites

Estou pensando em colocar um SELECT BOX no formulário e salvar através dele um número que será correspondente ao numero da imagem...

 

Então ao selecionar o numero no SELECT BOX significa que a imagem aparecerá em um determinado lugar...

 

 

Não esto conseguindo fazer com que salve no banco, é o mesmo script acima... so add o SELECT BOX no formulário.

 

Aguardo Resposta

Dudesigner

Compartilhar este post


Link para o post
Compartilhar em outros sites

dá uma olhada neste código:

 

<%
' Password é "Admin"
IntPass = "admin"
Pupload = "upload"
Response.Buffer = True
Response.Clear
Dim Name,Password,Login
If Not Session("Open") = "True" then%>
<title>Multiple File Uploads</title>
<BODY bgcolor=#3366CC onLoad="window.Introd.PassW.focus();">
<FORM name="Introd" method="post" action="<%=RedirName%>">
<table align=left border="1" bordercolor="#000000" cellspacing="0" cellpadding="0" width=250 bgcolor="#800000" style="border-collapse: collapse">
<tr><td align="center">
<P><font color="#FFFFFF"><font class=normal>Password:</font> </font><input type=password name=PassW ID=PassW size=8> <input type=submit class=boton2 name=Entrar ID=Entrar value=" Enter "></P>
</td></tr></table></form><br><br><br>
<p align=left style="font-family:verdana,helvetica,arial,sans serif;color:#000000;font-size:8pt;font-weight:bold;"><%= date%></p>
</BODY></HTML>
<%	Session("Open") = "True"
	Response.End
else
	if Session("Enter") = "1" then
	else	
		Login = "True"
		Password = Request.Form("Passw")
		If not Password = IntPass then Login= "False"
		If Login= "False" then
			Session.Abandon
			Response.Write "Senha Invalida!!! <A HREF=""java script:history.back(1)"">tente de novo"
			Response.End
		else
			Session("Enter") = "1"
				end if
	end if
End If
Sub BuildUploadRequest(RequestBin)
  
 
  if PosEnd = 0 then
  
	Response.Write "Corrija o formulário e tente novamente."
	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)
  on error resume next
  if UploadRequest.Item(name) then
	UploadFormRequest = UploadRequest.Item(name).Item("Value")
  end if  
End Function


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

serverupAction = CStr(Request.ServerVariables("URL")) & "?serverup=true"
If (Request.QueryString <> "") Then  
  if UploadQueryString <> "" then
	  serverupAction = serverupAction & "&" & UploadQueryString
  end if 
End If

If (CStr(Request.QueryString("serverup")) <> "") Then
 
  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>Ocorreu um erro ao salvar arquivos carregados!</B><br><br>"
		Response.Write "Nome Arquivo: " & Trim(AF_curPath) & UploadRequest.Item(AF_curKey).Item("FileName") & "<br>"
		Response.Write "Arquivo não existe ou está vazio.<br>"
		Response.Write "Corrija e <A HREF=""java script:history.back(1)"">tente de novo</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  
	  on error resume next
	  AF_strm2.SaveToFile Trim(Server.mappath(AF_curPath))& "\" & UploadRequest.Item(AF_curKey).Item("FileName"),2
	  if err then
		Response.Write "<B>Ocorreu um erro ao salvar arquivos carregados!</B><br><br>"
		Response.Write "Nome Arquivo: " & Trim(AF_curPath) & UploadRequest.Item(AF_curKey).Item("FileName") & "<br>"
		Response.Write "Talvez o diretório destino não exista, ou você não tem permissão.<br>"
		Response.Write "Corrija e <A HREF=""java script:history.back(1)"">tente de novo</b></font></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 & "&serverup=true"
else  
  UploadQueryString = "serverup=true"
end if  

%>
<html>
<head>
<title>Multiple File Uploads</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--

function getFileExtension(filePath) { //v1.0
  fileName = ((filePath.indexOf('/') > -1) ? filePath.substring(filePath.lastIndexOf('/')+1,filePath.length) : filePath.substring(filePath.lastIndexOf('\\')+1,filePath.length));
  return fileName.substring(fileName.lastIndexOf('.')+1,fileName.length);
}

function checkFileUpload(form,extensions) { //v1.0
  document.MM_returnValue = true;
  if (extensions && extensions != '') {
	for (var i = 0; i<form.elements.length; i++) {
	  field = form.elements[i];
	  if (field.type.toUpperCase() != 'FILE') continue;
	  if (field.value == '') {
		alert('File is required!');
		document.MM_returnValue = false;field.focus();break;
	  }
	  if (extensions.toUpperCase().indexOf(getFileExtension(field.value).toUpperCase()) == -1) {
		alert('This file is not allowed for uploading!');
		document.MM_returnValue = false;field.focus();break;
  } } }
}
//-->
</script>
</head>
<body bgcolor="#3366CC" text="#800000">
<table width="450" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr> 
	<td> 
	  <form name="ASP" method="post" action="<%=serverupAction%>" enctype="multipart/form-data" onSubmit="checkFileUpload(this,'');return document.MM_returnValue">
		<div align="center"> 
		  <input type="file" name="Files" size="20"> 
		  <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="#000000"> </font><input type="file" name="Files1" size="20">  </p>
		  <p> 
		  <input type="file" name="Files2" size="20">  </p>
		  <p> 
		  <input type="file" name="Files3" size="20">  </p>
		  <p> 
		  <input type="file" name="Files4" size="20">  </p>
		  <p> 
		  <input type="file" name="Files5" size="20">  </p>
		  <p> 
		  <input type="file" name="Files6" size="20">  </p>
		  <p> 
		  <input type="file" name="Files7" size="20">  </p>
		  <p><input type="reset" value="Reset" name="B1"><input type="submit" name="Submit" value="Upload"></div>
	  </form>
	</td>
  </tr>
</table>
</body>
</html>

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.