Ir para conteúdo

POWERED BY:

Arquivado

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

Nagib

Erro ao postar formulário

Recommended Posts

Olá,

 

Não estou conseguindo inserir uma rotina de upload em um form asp.

 

Para testar o form entre em http://www.mycurriculum.com.br/novodir/cl_newad.asp com senha e login "testando" e escolha a opção de incluir

novo anúncio. Digite algo no campo assunto e também algo no campo mensagem. Você irá ver que as informações não são enviadas para o

banco de dados.

 

Isso ocorreu porque no arquivo cl_newad.asp que está na pasta tem o seguinte código abaixo de upload que está entre as linhas 551 e 561:

 

<tr align="left" valign="middle"> 
                 <td width="150" style="background-color: #fcedb2;">
		<FONT class="fontepadrao tamanhofontepadrao negrito">Foto 01:</FONT>
		</td>
		<td colspan="3" width="450" style="background-color: #fff6d9">
		<form ACTION="upload.asp" METHOD="POST" ENCtype="multipart/form-data">
			<input type="FILE" SIZE="30" NAME="cl_foto_01">
			<input type="SUBMIT" VALUE="Upload!">
		</form >
  </td>
               </tr>

 

Eu consigo fazer o upload da imagem, no entanto, não consigo postar as informações título do anúncio e texto do anúncio para o banco de

dados ao apertar o botão gravar dados.

 

Quando removo esse trecho do código acima da linha 551 a linha 561 ele envia normalmente as informações para o banco de dados.

 

Para baixar os arquivos http://www.4shared.com/file/ITTc8ZB0/Material_asp.html

 

 

Obrigado e no aguardo

Compartilhar este post


Link para o post
Compartilhar em outros sites

olha este exemplo de upload multiplo de arquivo e para pegar os valores dos campos assunto e campo mensagem, recupere atraves do request

 

<%
' Password is "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 "Invalid Password!!! <A HREF=""javascript:history.back(1)"">try again"
		Response.End
	else
		Session("Enter") = "1"
			end if
end if
End If
Sub BuildUploadRequest(RequestBin)


 if PosEnd = 0 then

   Response.Write "Please correct the form uploads and try again."
   Response.End
 end if
 boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
 boundaryPos = InstrB(1,RequestBin,boundary)

 Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
   'Members variable of objects are put in a dictionary object
   Dim UploadControl
   Set UploadControl = CreateObject("Scripting.Dictionary")
   'Get an object name
   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>An error has occured saving uploaded file!</B><br><br>"
       Response.Write "Filename: " & Trim(AF_curPath) & UploadRequest.Item(AF_curKey).Item("FileName") & "<br>"
       Response.Write "File does not exists or is empty.<br>"
       Response.Write "Please correct and <A HREF=""javascript:history.back(1)"">try again</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>An error has occured saving uploaded file!</B><br><br>"
       Response.Write "Filename: " & Trim(AF_curPath) & UploadRequest.Item(AF_curKey).Item("FileName") & "<br>"
       Response.Write "Maybe the destination directory does not exist, or you don't have write permission.<br>"
       Response.Write "Please correct and <A HREF=""javascript:history.back(1)"">try again</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

Pessoal, obrigado pelas dicas e pelo script. No entanto eu preciso que meu arquivo funcione. Alguém poderia baixar e editar ele ou baixar e me dizer oque devo alterar para que o botão gravar dados funcione ?

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.