Foros del Web » Programando para Internet » ASP Clásico »

Subir imagenes en asp

Estas en el tema de Subir imagenes en asp en el foro de ASP Clásico en Foros del Web. Hola!! tengo el siguiente problema, estoy haciendo un sitio de publicacion de propiedades en donde se pueden subir imagenes del mismo, el error me sale ...
  #1 (permalink)  
Antiguo 02/05/2009, 08:25
 
Fecha de Ingreso: abril-2009
Mensajes: 10
Antigüedad: 16 años
Puntos: 0
Subir imagenes en asp

Hola!! tengo el siguiente problema, estoy haciendo un sitio de publicacion de propiedades en donde se pueden subir imagenes del mismo, el error me sale cuando modifico los datos de un inmueble ya publicado y quiero subirle mas imagenes de las que ya tiene.

rs.Addnew
rs.fields("imagen") = FileName
rs.fields("idPropiedad") = request.QueryString("id")
if existePrincipal = true then
rs.fields("principal") = "no"
else
rs.fields("principal") = "si"
end if
rs.Update
rs.close

El error sale en la primera línea rs.Addnew, como puedo cambiarlo para que me deje subir otras imagenes una vez publicado el inmueble.

Gracias.
  #2 (permalink)  
Antiguo 02/05/2009, 12:06
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 23 años, 3 meses
Puntos: 146
Respuesta: Subir imagenes en asp

¿qué error da?
¿cómo abres la conexión?
  #3 (permalink)  
Antiguo 02/05/2009, 12:25
 
Fecha de Ingreso: abril-2009
Mensajes: 10
Antigüedad: 16 años
Puntos: 0
Respuesta: Subir imagenes en asp

Cita:
Iniciado por Myakire Ver Mensaje
¿qué error da?
¿cómo abres la conexión?
ERROR:

Microsoft JET Database Engine error '80040e14'

Syntax error (missing operator) in query expression 'imagen.[idpropiedad]='.

línea 184 : rs.open sql, base, 2,3
  #4 (permalink)  
Antiguo 02/05/2009, 12:55
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 23 años, 3 meses
Puntos: 146
Respuesta: Subir imagenes en asp

Ok, no abres el rs de solo lectura, entonces el addnew no creo que sea el que da error, y menos por que el error que manda pareciera que lo hace en el .Open ...

Cuál es el QueryString del recordSet?
  #5 (permalink)  
Antiguo 02/05/2009, 13:12
 
Fecha de Ingreso: abril-2009
Mensajes: 10
Antigüedad: 16 años
Puntos: 0
Respuesta: Subir imagenes en asp

Cita:
Iniciado por Myakire Ver Mensaje
Ok, no abres el rs de solo lectura, entonces el addnew no creo que sea el que da error, y menos por que el error que manda pareciera que lo hace en el .Open ...

Cuál es el QueryString del recordSet?
Perdon que sea tan largo pero me como no tengo mucha idea de asp prefiero enviarte el codigo entero. El tema es que el inmueble ya publicado con su foto al querer agregarle otra foto me sale el error.

CODIGO:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Grupo inmobiliario</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<% if session("autorizado") <> true then
response.redirect "index.asp"
end if%>
<div class="gContenedor" align="center">
<div class="contenedor2" >
<div class="contenedor" >
<!--#include file="includes/header.asp"-->
<div class="separador"></div>
<!-- pepo aca va el contenido de cada sección-->
<div class="center" align="left">
<div class="barraMain">&nbsp;&nbsp;Agregar nueva propiedad - paso 3 - subir imagenes </div>
<br>Para una correcta visualización se recomienda subir imagenes cuyo tamaño no sea superior a <strong>640 x 480 pixeles</strong>.<br>
<br>
<div class="banner3"><br>
<%response.buffer=true
Func = Request("Func")
if isempty(Func) Then
Func = 1
End if
Select Case Func
Case 1
link = request.QueryString("id")
%>

<FORM ENCTYPE="multipart/form-data" ACTION="subirimagenes.asp?func=2&id=<%= request.QueryString("id") %>" METHOD=POST id=form1 name=form1>
<TABLE width="325" border="1" align="center" cellpadding="5" cellspacing="5" class="tit5">
<TR>
<TD>
<p><b>Instrucciones:</b></p>
<ol>
<li>Pulsa en el botón examinar y elige la imagen que deseas.</li>
<li>Luego pulsa el botón subir. </li>
<li>Espere, recibirá la notificación
al terminar de subir el archivo.</li>
</ol></TD>
</TR>
<TR>
<TD ><STRONG>Nombre
de la imagen a subir ...</STRONG> <br>
<br>

<INPUT NAME=File1 SIZE=20 TYPE=file>
</font>
<INPUT type="submit" value="Subir"></TD>
</TR>
</TABLE>
<table width="0" border="0" align="center">
<tr>
<td>&nbsp;</td>
<td><a href="userP.asp"><img src="img/saltpaso.gif" border="0"></a></td>
<td>&nbsp;</td>
</tr>
</table>
</FORM>
<p>
<%
Case 2
ForWriting = 2
adLongVarChar = 201
lngNumberUploaded = 0

'Get binary data from form
noBytes = Request.TotalBytes
binData = Request.BinaryRead (noBytes)
'convery the binary data to a string
Set RST = CreateObject("ADODB.Recordset")
LenBinary = LenB(binData)

if LenBinary > 0 Then
RST.Fields.Append "myBinary", adLongVarChar, LenBinary
RST.Open
RST.AddNew
RST("myBinary").AppendChunk BinData
RST.Update
strDataWhole = RST("myBinary")
End if
'Creates a raw data file for with all
' data sent. Uncomment for debuging.
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f = fso.OpenTextFile(server.mappath(".") & "\raw.txt", ForWriting, True)
'f.Write strDataWhole
'set f = nothing
'set fso = nothing
'get the boundry indicator
strBoundry = Request.ServerVariables ("HTTP_CONTENT_TYPE")
lngBoundryPos = instr(1,strBoundry,"boundary=") + 8
strBoundry = "--" & right(strBoundry,len(strBoundry)-lngBoundryPos)
'Get first file boundry positions.
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
Do While lngCurrentEnd > 0
'Get the data between current boundry an
' d remove it from the whole.
strData = mid(strDataWhole,lngCurrentBegin, lngCurrentEnd - lngCurrentBegin)
strDataWhole = replace(strDataWhole,strData,"")

'Get the full path of the current file.
lngBeginFileName = instr(1,strdata,"filename=") + 10
lngEndFileName = instr(lngBeginFileName,strData,chr(34))
'Make sure they selected at least one fi
' le.
if lngBeginFileName = lngEndFileName and lngNumberUploaded = 0 Then

Response.Write "<H2> Ha ocurrido el siguiente error.</H2>"
Response.Write "Debes elegir un archivo para subir"
Response.Write "<BR><BR>Pulsa el botón volver, realiza la corrección."
Response.Write "<BR><BR><INPUT type='button' onclick='history.go(-1)' value='<< Volver' id='button'1 name='button'1>"
Response.End
End if
'There could be one or more empty file b
' oxes.
if lngBeginFileName <> lngEndFileName Then
strFilename = mid(strData,lngBeginFileName,lngEndFileName - lngBeginFileName)
'Creates a raw data file with data betwe
' en current boundrys. Uncomment for debug
' ing.
'Set fso = CreateObject("Scripting.FileSystemObject")
'Set f = fso.OpenTextFile(server.mappath(".") & "\raw_" & lngNumberUploaded & ".txt", ForWriting, True)
'f.Write strData
'set f = nothing
'set fso = nothing

'Loose the path information and keep just the file name.
tmpLng = instr(1,strFilename,"\")
Do While tmpLng > 0
PrevPos = tmpLng
tmpLng = instr(PrevPos + 1,strFilename,"\")
Loop

FileName = right(strFilename,len(strFileName) - PrevPos)

'Get the begining position of the file data sent.
'if the file type is registered with the browser then there will be a Content-Type
lngCT = instr(1,strData,"Content-Type:")

if lngCT > 0 Then
lngBeginPos = instr(lngCT,strData,chr(13) & chr(10)) + 4
Else
lngBeginPos = lngEndFileName
End if
'Get the ending position of the file dat
' a sent.
lngEndPos = len(strData)

'Calculate the file size.
lngDataLenth = lngEndPos - lngBeginPos
'Get the file data
strFileData = mid(strData,lngBeginPos,lngDataLenth)
'Create the file.
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(server.mappath("imagenes") & "/" & FileName,ForWriting, True)
f.Write strFileData
Set f = nothing
Set fso = nothing

lngNumberUploaded = lngNumberUploaded + 1

End if

'Get then next boundry postitions if any
lngCurrentBegin = instr(1,strDataWhole,strBoundry)
lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
loop


Response.Write "Archivo subido <BR>"
Response.Write "El archivo ya está en el servidor.<BR>"
Response.Write "Elegir la siguiente imagen.<BR>" %>


<a href="userP.asp" class="tit5"><img src="img/misprop.gif" border="0"></a> <a href="subirimagenes.asp?id=<%= request.QueryString("id") %>" class="tit5"><img src="img/misimag.gif" border="0"></a>

<%
base= "PROVIDER=Microsoft.jet.oledb.4.0;data source="& server.mappath("includes/inmobiliaria.mdb")&";"
sql = " select * from imagen where imagen.[idpropiedad]=" & request.QueryString("id") &"; "
set rs=server.CreateObject("ADODB.Recordset")
rs.open sql, base, 2,3
do while not rs.eof
if rs.fields("principal")="si" then
existePrincipal = true
end if
rs.movenext
loop
rs.Addnew
rs.fields("imagen") = FileName
rs.fields("idPropiedad") = request.QueryString("id")
if existePrincipal = true then
rs.fields("principal") = "no"
else
rs.fields("principal") = "si"
end if
rs.Update
rs.close
End Select
%>
<br>
<br>

</div>
</div><!--cierre center-->
<!-- -->
<!--#include file="includes/left.asp"-->
<div class="separador"></div>
</div><!--cierre contenedor-->
</div><!--cierre contenedor2-->
</div><!--cierre gContenedor-->
</body>
</html>
  #6 (permalink)  
Antiguo 02/05/2009, 21:05
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 23 años, 3 meses
Puntos: 146
Respuesta: Subir imagenes en asp

No revisé muy cuidadosamente tu código, pero a golpe de vista detecté que tienes "harcodeado" el nombre del campo que agregas en tiempo de ejecución:

RST.Fields.Append "myBinary", adLongVarChar, LenBinary

Esto haría que si quieres agregar un segundo campo con ese mismo nombre, te mande un error. Debes de agregarle un índice a tu campo nuevo si quieres que te funcione así, aunque en lo personal, en lugar de insertar campos, yo haría una tabla detalle con las imagenes ligada a los datos de la propiedad, es decir, Una propiedad puede tener 0 o N imágenes.

Saludos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:04.