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

problemas con subir archivos y agregar registro simultaneamente

Estas en el tema de problemas con subir archivos y agregar registro simultaneamente en el foro de ASP Clásico en Foros del Web. Hola amigos, les cuento tengoe ste código para subir imagenes a una carpeta de mi servidor.... bueno originalmente no es asi supongo que mas de ...
  #1 (permalink)  
Antiguo 21/06/2005, 19:51
Avatar de El_Metallick  
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 22 años, 5 meses
Puntos: 16
problemas con subir archivos y agregar registro simultaneamente

Hola amigos, les cuento tengoe ste código para subir imagenes a una carpeta de mi servidor.... bueno originalmente no es asi supongo que mas de alguno lo conoce es el de asptutor saveany.... bueno le modifique el nombre y le agregue campos al formuario de tal manera que al mismo tiempo de subir la imagen agregue un registro a la base de datos con los datos del form... bueno la cosa es que si le borro lo que aparece en rojo me queda todo bien pero si se lo dejo me tira error en la linea 199 este error:

Error de Microsoft VBScript en tiempo de ejecuciónerror '800a004c'
Ruta de acceso no encontrada
/pruebas/catalogo/form_agregar_producto.asp, line 199

y no se porque les dejo el cñodigo agradezco su ayuda
Código:
<%
response.buffer = true
%>
<html>
<head>
<title>Agregar Producto</title>
<link rel="stylesheet" type="text/css" href="estilo.css">
</head>
<body>
<%
 'Declaración de variables
 Dim conn
 Dim rs
 Dim sql
 'Establecemos la conección a la base de datos
 Set conn = Server.CreateObject("ADODB.Connection")
 conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("catalogo.mdb"))

 'Creación de la sentencia SQL correspondiente (cambiar el valor de tabla por el nombre de la tabla que queremos seleccionar)
 sql="Select * From categorias"

 'Ejecución de la orden
 Set rs = Conn.Execute(sql)

Func = Request("Func")
if isempty(Func) Then
Func = 1
End if
Select Case Func
Case 1
%>
<form enctype="multipart/form-data" action="form_agregar_producto.asp?func=2" method="post" id="form1" name="form1"> 
<table border="0" width="100%" cellspacing="0" cellpadding="0" align="center">
 <tr>
  <td width="20%" valign="top">
   <!--#include file="admin/inc/menu.inc" -->
  </td>
  <td width="80%" valign="top">
  <form method="post" action="agregar_producto.asp" target="_blank">
   <table border="1" bordercolor="#DFE8FF" width="70%" cellspacing="0" cellpadding="0" align="center">
	<tr>
  <td>
   <table border="0"  width="100%" cellspacing="0" cellpadding="2">
	<tr>
		<td width="100%" bgcolor="#DFE8FF" class="text">Agregar Registro</td>
	   </tr>
	<tr>
		<td width="100%" bgcolor="#EFEFEF" class="text">
   <table border="0" cellspacing="0" cellpadding="0" align="center">
		  <tr>
		   <td width="8%" class="text">Categoría:</td>
		   <td width="92%">
	  <select name="categoria" style="<% = SelectEstilo %>">
	<% Do While Not rs.Eof %>
	<option value="<% = rs("id_categoria") %>"><% = rs("nombre_categoria") %></option>
	<%
	rs.MoveNext
	Loop
	%>
   </select></td>
		  </tr>
		  <tr>
		   <td width="8%" class="text">Imágen:</td>
		   <td width="92%"><input name="File1" size="20" type="file" style="<% = InputEstilo %>"></td>
		  </tr>
		  <tr>
		   <td width="8%" class="text">Marca:</td>
		   <td width="92%"><input type="text" name="marca" size="20" style="<% = InputEstilo %>"></td>
		  </tr>
		  <tr>
		   <td width="8%" class="text">Modelo:</td>
		   <td width="92%"><input type="text" name="modelo" size="20" style="<% = InputEstilo %>"></td>
		  </tr>
		  <tr>
		   <td width="8%" class="text">Descripción:</td>
		   <td width="92%"><input type="text" name="descripcion" size="20" style="<% = InputEstilo %>"></td>
		  </tr>
		  <tr>
		   <td width="8%" class="text">Precio:</td>
		   <td width="92%"><input type="text" name="precio" size="20" style="<% = InputEstilo %>"></td>
		  </tr>
	<tr>
		   <td width="8%">&nbsp;</td>
		   <td width="92%" class="text">Nota: El precio es sin el simblo $</td>
		  </tr>
		 </table>
		</td>
	   </tr>
   </table>
  </td>
 </tr>
   </table>
   <p align="center"><input type="submit" value="Agregar" style="<% = BotonEstilo %>"></p>
  </form>
  </td>
 </tr>
</table>
<%
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 da
' ta 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 jus
' t 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 d
' ata sent.
'if the file type is registered with the
' browser then there will be a Content-Typ
' e
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"
Response.Write lngNumberUploaded & " archivo ya está en el servidor.<br>"
Response.Write "<br><br><INPUT type='button' onclick='document.location=" & chr(34) & "form_agregar_producto.asp" & chr(34) & "' value='<< Volver' id='button'1 name='button'1>" 
End Select 
%>

</BODY>
</HTML>
__________________
Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!!
  #2 (permalink)  
Antiguo 21/06/2005, 22:27
Avatar de mamon  
Fecha de Ingreso: enero-2002
Ubicación: Lima
Mensajes: 1.302
Antigüedad: 23 años, 3 meses
Puntos: 3
la linea del error es esta?
Set f = fso.OpenTextFile(server.mappath(".") & "\imagenes" &_

pucha no sé que tiene q ver lo rojo, no he leido todo tu código xq en vdd está bien largo! no malees... en vdd pa q te podamos ayudar trata encontrar más o menos x donde puede ser que esté el problema, xq bien maleado q leamos todo y lo entendamos y encontremos el roche... tb ese es un problema de copiar y pegar código.. encunetras un error y no sabes xq de las cosas... pero bueno.. trata de hacernolas más fácil para poder ayudarte pes
__________________
Yo si sé lo que es trabajar duro, porque lo he visto.
  #3 (permalink)  
Antiguo 22/06/2005, 11:48
Avatar de El_Metallick  
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 22 años, 5 meses
Puntos: 16
la linea del error es esa efectivamente, lo rojo es que si lo saco funciona todo bien pero al agregarle campos al form distintos que el <input name="File1" size="20" type="file"> me tira el error... no se que sacar porque como no hice yo el script y tampoco soy muy avanzado en esto no se que sacar o no pues.... se que es un royo leerso todo eso pero de verdad que no se porque pasa... se me ocurre que es al rescatar el campo porque si funciona bien con solo ese campo y no funciona cuando le agrego otro(s).... bueno eso agradeceria alguna sujerencia o algun otro script ya hecho y funcionando para solucionar el problema... muchas gracias
__________________
Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!!

Última edición por El_Metallick; 22/06/2005 a las 12:24
  #4 (permalink)  
Antiguo 22/06/2005, 12:32
Avatar de mamon  
Fecha de Ingreso: enero-2002
Ubicación: Lima
Mensajes: 1.302
Antigüedad: 23 años, 3 meses
Puntos: 3
en vdd yo jamás he usado ese componente.. yo que tú leo mejor el manual de donde lo sacaste
__________________
Yo si sé lo que es trabajar duro, porque lo he visto.
  #5 (permalink)  
Antiguo 22/06/2005, 13:20
Avatar de El_Metallick  
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 22 años, 5 meses
Puntos: 16
no tiene manual... es un articulo de asptutor
__________________
Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!!
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 05:58.