Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Salve galera,
Novamente dúvida em upload..hehe
to com um código aqui de uma página qeu faz inclusão de produtos em uma base em access...
o código é o seguinte!
<% Response.Expires = 0 %>
<!--#Include file="upload.asp"-->
<%
' Chamando Funções, que fazem o Upload funcionar
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
%>
<!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">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/estilos.css" rel="stylesheet" type="text/css">
<title>Painel Administrativo - J2</title>
<style type="text/css"> margin-left: 19px;
margin-top: 19px;
margin-right: 19px;
margin-bottom: 19px;
}</style></head>
<body bgcolor="#000000">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" bgcolor="#000000"><table width="970" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="117"><!--#Include file="topo_.asp"--></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center" bgcolor="#000000"><table width="970" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="21"><img src="images/painel_13.jpg" width="21" height="28" /></td>
<td width="931" bgcolor="#FFFFFF"> </td>
<td width="18"><img src="images/painel_14.jpg" width="18" height="28" /></td>
</tr>
<tr>
<td width="21" bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="19%"><!--#Include file="menu_.asp"--></td>
<td width="81%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center"><table width="730" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="30" align="left" valign="top" class="tarja">Cadastro de Produtos</td>
</tr>
<%
Dim acao,lista_categoria
acao = Request.QueryString("acao")
If acao="incluir" Then
If (Request.Form("cat_id") = "nulo") Then acao = "erro" End If
If (Request.Form("nome") = "") Then acao = "erro" End If
If (Request.Form("descricaop") = "") Then acao = "erro" End If
If (Request.Form("descricaog") = "") Then acao = "erro" End If
If (Request.Form("preco") = "") Then acao = "erro" End If
If (Request.Form("imagem") = "") Then acao = "erro" End If
If (Request.Form("disp") = "") Then acao = "erro" End If
cat_id = Replace(UploadRequest.Item("cat_id").Item("Value"),"'","")
nome = Replace(UploadRequest.Item("nome").Item("Value"),"'","")
descricaop = Replace(UploadRequest.Item("descricaop").Item("Value"),"'","")
descricaog = Replace(UploadRequest.Item("descricaog").Item("Value"),"'","")
preco = Replace(UploadRequest.Item("preco").Item("Value"),"'","")
foto = Replace(UploadRequest.Item("foto").Item("Value"),"'","")
disp = Replace(UploadRequest.Item("disp").Item("Value"),"'","")
' Tipo de arquivo que esta sendo enviado
tipo_foto = UploadRequest.Item("foto").Item("ContentType")
' Caminho completo dos arquivos enviados
caminho_foto = UploadRequest.Item("foto").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("foto").Item("Value")
' pasta onde as imagens serao guardadas
pasta = Server.MapPath("/fotos/")
nome_foto = "/"&nome_foto
' pasta + nome dos arquivos
cfoto = 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
End If
If acao = "incluir" AND cat_id = "nulo" Then
%>
<tr>
<td height="20" align="left" class="menu"><strong>Selecione uma categoria!</strong></td>
</tr>
<%
acao = "erro"
End If
If acao = "erro" Then
%>
<tr>
<td height="20" align="left" class="menu"><strong>Nenhum campo pode estar em branco!</strong></td>
</tr>
<%
End If
If acao = "incluir" Then
Dim chk_prod,cat_id,nome,descricaop,descricaog,preco,imagem,disp
set chk_prod = lojaDB.Execute("SELECT nome FROM produtos WHERE nome='"& Request.Form("nome") & "'")
If Not (chk_prod.EOF) Then
%>
<tr>
<td height="20" align="left" class="menu"><strong>Ops, Já existe um produto cadastrado com esse nome!</strong></td>
</tr>
<%
Else
lojaDB.Execute("INSERT INTO produtos(cat_id,nome,descricaop,descricaog,preco,imagem,disp)" & _
"VALUES('" & cat_id & "','" & nome & "','" & descricaop & "','" & _
descricaog & "','" & preco & "','" & foto & "','" & disp & "')")
%>
<tr>
<td height="20" align="left" class="menu"><strong>O produto foi cadastrado com sucesso!</strong></td>
</tr>
<%
acao = "ok"
End If
End If
If Not (acao = "ok") Then
%>
<tr>
<td height="20" align="left" class="menu">
<form method=post name=cadastro action=./cad_prod_.asp?acao=incluir enctype="multipart/form-data">
<table width="440" border=0 cellpadding="0" cellspacing="0" class="menu">
<tr valign=top>
<td height="25" align="right" valign="top" class="menu">Nome:</td>
<td width="10" valign="top"> </td>
<td height="30" valign="top"><input name=nome type=text class="menu" value="<%=nome%>" size=50 maxlength=60></td>
</tr>
<tr valign=top>
<td height="25" align="right" valign="top" class="menu">Categoria:</td>
<td valign="top"> </td>
<td height="30" valign="top">
<select name=cat_id class="menu">
<option value=nulo>Selecione uma Categoria</option>
<%
set lista_categoria = lojaDB.Execute("SELECT * FROM categorias")
While not lista_categoria.EOF
%>
<option value="<%=lista_categoria("id")%>" <%If (lista_categoria("id") = cat_id) Then Response.Write "selected" End If%>><%=lista_categoria("nome")%></option>
<%
lista_categoria.MoveNext
Wend
%>
</select></td>
</tr>
<tr valign=top>
<td height="25" align="right" valign="top" class="menu">Descrição resumida:</td>
<td valign="top"> </td>
<td height="45" valign="top"><label>
<textarea name="descricaop" id="descricaop" cols="37" rows="2"><%=descricaop%>
</textarea>
</label></td>
</tr>
<tr valign=top>
<td height="25" align="right" valign="top" class="menu">Descrição completa:</td>
<td valign="top"> </td>
<td height="63" valign="top"><textarea name="descricaog" id="descricaog" cols="37" rows="3"><%=descricaog%>
</textarea>
<br /></td>
</tr>
<tr valign=top>
<td height="25" align="right" valign="top" class="menu">Preço:</td>
<td valign="top" class="menu"> </td>
<td height="30" valign="top" class="menu"><input name=preco type=text class="menu" value="<%=FormatCurrency(preco)%>" size=8></td>
</tr>
<tr valign=top>
<td height="25" align="right" valign="top" class="menu">Imagem:</td>
<td valign="top"> </td>
<td height="30" valign="top"><input name="foto" type="file" class="caixa_texto" id="foto" /></td>
</tr>
<tr valign=top>
<td height="25" align="right" valign="top" class="menu">Disponível:</td>
<td valign="top"> </td>
<td height="30" valign="top">
<select name=disp class="menu">
<option value="S" <%
If acao = "erro" Then
If disp = "S" Then Response.Write "selected" End If
Else
%>selected<%
End If%>>Sim</option>
<option value="N" <%If disp = "N" Then Response.Write "selected" End If%>>Não</option>
</select></td>
</tr>
<tr align=center>
<td align="right" valign="middle"> </td>
<td></td>
<td align="right"><input type=image src="images/cadastrar.gif" border=0 /></td>
</tr>
</table>
</form>
</td>
</tr>
<% End If %>
<tr>
<td height="20" align="left" class="menu"> </td>
</tr>
<tr>
<td height="20" align="left" class="menu"><p><br />
Os produtos devem estar dentro de algum departamento.<br />
<br />
Por exemplo:<br />
<br />
Mouses, Teclados, Monitores, notebooks<br />
Pertencem ao departamento de Informática.<br />
<br />
Celulares, Telefones sem fio, Identificador de chamadas.<br />
Pertencem ao departamento de Telefonia.<br />
<br />
Para cadastrar um produto, preencha os campos acima e clique no botão "Cadastrar"</p>
</td>
</tr>
<tr>
<td height="20" align="left" class="menu"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
<td bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td width="21"><img src="images/painel_21.jpg" width="21" height="24" /></td>
<td bgcolor="#FFFFFF"> </td>
<td><img src="images/painel_23.jpg" width="18" height="24" /></td>
</tr>
</table></td>
</tr>
<tr>
<td align="center" bgcolor="#000000"><table width="970" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="3"><!--#Include file="rodape_.htm"--></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>Request object error 'ASP 0207 : 80004005'
Cannot use Request.Form
/novaloja/novo_adm/cad_prod_.asp, line 66
Cannot use Request.Form collection after calling BinaryRead.
Eu fiz o seguinte,
Alterei da linha 66 à 72 que são essas:
If (Request.Form("cat_id") = "nulo") Then acao = "erro" End If
If (Request.Form("nome") = "") Then acao = "erro" End If
If (Request.Form("descricaop") = "") Then acao = "erro" End If
If (Request.Form("descricaog") = "") Then acao = "erro" End If
If (Request.Form("preco") = "") Then acao = "erro" End If
If (Request.Form("foto") = "") Then acao = "erro" End If
If (Request.Form("disp") = "") Then acao = "erro" End If
Alterei por isso aí:
If UploadRequest.Item("cat_id") = "nulo" Then acao = "erro" End If
If UploadRequest.Item("nome") = "" Then acao = "erro" End If
If UploadRequest.Item("descricaop") = "" Then acao = "erro" End If
If UploadRequest.Item("descricaog") = "" Then acao = "erro" End If
If UploadRequest.Item("preco") = "" Then acao = "erro" End If
If UploadRequest.Item("foto") = "" Then acao = "erro" End If
If UploadRequest.Item("disp") = "" Then acao = "erro" End If
Só que aí daria o seguinte erro:
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment
/novaloja/novo_adm/cad_prod_.asp, line 66
Alguem sabe o por que desse erro e como corrigir isso???
Valeu galera!
Carregando comentários...