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

problema con Post.Upload

Estas en el tema de problema con Post.Upload en el foro de ASP Clásico en Foros del Web. Hola tengo un archivo ASP que llama a una funcion de otro archivo ASP, la cual se encarga de subir archivos al servidor (tarea de ...
  #1 (permalink)  
Antiguo 18/06/2008, 11:42
 
Fecha de Ingreso: mayo-2007
Mensajes: 239
Antigüedad: 17 años, 11 meses
Puntos: 0
problema con Post.Upload

Hola tengo un archivo ASP que llama a una funcion de otro archivo ASP, la cual se encarga de subir archivos al servidor (tarea de administrador) el tema es que esa funcion al ir a subir una imagen me da un fallo en esta linea:

Post.Upload RUTA (donde ruta es una carpeta del servidor)
Podria ser tema del servidor de que no tenga permisos para escribir en la carpeta del servidor? y entonces no pueda copiar el archivo en la carpeta¿
a que otras causas puede deberse este problema??

tambien qusiera saber que es lo que hace este codigo:
<form name="Formulario" style="margin:0px;" action="<%=URLRaiz%>Includes/Utils/Popup.asp" method="POST" enctype="multipart/form-data">

gracias un saludo!!!

Última edición por piskui; 18/06/2008 a las 11:54
  #2 (permalink)  
Antiguo 18/06/2008, 11:51
 
Fecha de Ingreso: mayo-2008
Mensajes: 77
Antigüedad: 16 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

Puede ser un problema del servidor si, pero si no das un poco mas de informacion no puedo decirte nada mas.
Otras causas pueden ser que este mal:

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("ssdd.mdb"))


o por ejemplo que el cerrojo este mal en la apertura?¿?¿
Postea el codigo
  #3 (permalink)  
Antiguo 18/06/2008, 11:58
 
Fecha de Ingreso: mayo-2007
Mensajes: 239
Antigüedad: 17 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

no usa conexion con access sino SQL, y de la conexion no es porque no existe ningun problema en conectar. Esa sentencia esta en otro ASP supongo porque con el que estoy tratando no tiene cadena de conexion.
A que te refieres con que el cerrojo este mal en la apertura? no entiendo? como se solucionaria?

El codigo es:
dim ruta = Request.ServerVariables("APPL_PHYSICAL_PATH") & "Carpeta\"
Set Post = Server.CreateObject("ActiveFile.Post")
Post.Upload ActiveFile_DirTemporal
<-esta es la linea que da el fallo
  #4 (permalink)  
Antiguo 18/06/2008, 12:28
 
Fecha de Ingreso: mayo-2008
Mensajes: 77
Antigüedad: 16 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

Si conectas lo del cerrojo da igual eso es para el recorset, bueno me pilllas con prisa pero si quieres te puedo pegar el codigo del aspupload adaptado para subir archivos y que los renombra y tal, asi puedes probarlo y si no va el por los permisos del servidor
  #5 (permalink)  
Antiguo 19/06/2008, 05:22
 
Fecha de Ingreso: mayo-2007
Mensajes: 239
Antigüedad: 17 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

ok gracias cuando puedas me pasas el codigo, gracias. un saludo.
  #6 (permalink)  
Antiguo 20/06/2008, 09:35
 
Fecha de Ingreso: mayo-2008
Mensajes: 77
Antigüedad: 16 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

siento la tardanza e estado muy liado con un "problemilla" recuerda lo que voy a pegar es el aspupload lo puedes buscar en google, lo modifique para renombrar archivos y que no se pisen si se llaman igual.

<%
option explicit
Response.Expires = -1
Server.ScriptTimeout = 600
%>
<!-- #include file="freeaspupload.asp" -->
<!--#include file="Conexion/bd_pinar.asp" -->
<%

' ************************************************** **
' Cambiar el valor de la siguiente variable
' para indicar el directorio de destino.
' El directorio indicado debe tener permisos de escritura
' de caso contrario el script fallará mostrando un error.
Dim uploadsDirVar
uploadsDirVar = Server.MapPath("../fotos")
' ************************************************** **
dim temporal
function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey, resumen
Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)
' If something fails inside the script, but the exception is handled
If Err.Number <> 0 then Exit function
SaveFiles = ""
ks = Upload.UploadedFiles.keys
if (UBound(ks) <> -1) then
resumen = "<B>Archivo subido:</B> "
for each fileKey in Upload.UploadedFiles.keys
resumen = resumen & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
temporal = Upload.UploadedFiles(fileKey).FileName

next
else
resumen = "El nombre del archivo especificado en el formulario no es valido en el sistema."
end if
'comentar la siguiente linea si no se desea mostrar el resumen
SaveFiles = resumen

dim rst
dim Cnn
dim codigo
Set Cnn = Server.CreateObject("ADODB.Connection")
set rst = Server.CreateObject("ADODB.RecordSet")
rst.ActiveConnection = conexion
rst.source = "SELECT * FROM inmueble ORDER BY codigo DESC"
rst.CursorType = 0
rst.CursorLocation = 3
rst.LockType = 3
rst.Open()
cnn.Open= conexion



codigo = (rst.Fields.Item("codigo").Value)

response.Write(codigo)



'Declaracion de variables
Dim FSO, Fich , NombreAnterior, NombreNuevo
'Inicialización
NombreAnterior = temporal
NombreNuevo =cstr(codigo) &"_" &temporal
temporal = NombreNuevo
response.Write(temporal)
' Instanciamos el objeto
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
' Asignamos el fichero a renombrar a la variable fich
Set Fich = FSO.GetFile(Server.MapPath("../fotos/" & NombreAnterior))
' llamamos a la funcion copiar,
'y duplicamos el archivo pero con otro nombre
Call Fich.Copy(Server.MapPath("../fotos/" & NombreNuevo))
' finalmente borramos el fichero original
Call Fich.Delete()

Set Fich = Nothing
Set FSO = Nothing





end function
%>

<HTML>
<HEAD>
<TITLE>Test Free ASP Upload</TITLE>
</HEAD>
<BODY>
<br>
<div style="border-bottom: #A91905 2px solid;font-size:16">Subir archivos</div>
<div style='margin-left:150'>

<form name="frmSend" method="POST" enctype="multipart/form-data" action="pruebaupload.asp">
Logotipo: <input name="attach1" type="file" size="35"><br>

<br>
<input type=submit value="Subir">
</form>

<BR></div>
<%
dim imag
dim con2
dim sql2
dim rs
'solo llamo al UPLOAD si hay envio de formulario
if Request.ServerVariables("REQUEST_METHOD") = "POST" then
'Hace el upload de los archivos enviados y muestra el resumen
response.write SaveFiles()


'creamos un recorset para recuperar la PK de la ultima insercion para colocar el archivo de la imagen en su sitio

dim cnn2
dim rst2
dim codigo2
Set Cnn2 = Server.CreateObject("ADODB.Connection")
set rst2 = Server.CreateObject("ADODB.RecordSet")
rst2.ActiveConnection = conexion
rst2.source = "SELECT codigo FROM inmueble ORDER BY codigo DESC"
rst2.CursorType = 0
rst2.CursorLocation = 3
rst2.LockType = 3
rst2.Open()
cnn2.Open= conexion



codigo2 = (rst2.Fields.Item("codigo").Value)


rst2.close
set rst2= nothing






'a la varibale imagen le concatenamos la ruta donde se copiaran las fotos
imag = "./fotos/" & temporal

dim Con3
Set Con3 = Server.CreateObject("ADODB.Connection")
con3.Open conexion
'actualizamos con un update la tabla centros
sql2="update inmueble set foto= '"&imag&"' where codigo = '"&cstr(codigo2)&"' "


set rs=con3.execute(sql2)
'response.Redirect("PruebaUpload.asp")
con3.close


set rs = nothing
response.Redirect("../index.html")
end if

%>





</BODY>
</HTML>


fiate en el que las opciones explicitas estan declaradas y en los casting a las variables

Última edición por loverpiu; 20/06/2008 a las 10:14
  #7 (permalink)  
Antiguo 20/06/2008, 09:36
 
Fecha de Ingreso: mayo-2008
Mensajes: 77
Antigüedad: 16 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

y este es el freeaspupload el tor archivo que te hace falta


<%
' For examples, documentation, and your own free copy, go to:
' http://www.freeaspupload.net
' Note: You can copy and use this script for free and you can make changes
' to the code, but you cannot remove the above comment.

'Changes:
'Aug 2, 2005: Add support for checkboxes and other input elements with multiple values

Class FreeASPUpload
Public UploadedFiles
Public FormElements

Private VarArrayBinRequest
Private StreamRequest
Private uploadedYet

Private Sub Class_Initialize()
Set UploadedFiles = Server.CreateObject("Scripting.Dictionary")
Set FormElements = Server.CreateObject("Scripting.Dictionary")
Set StreamRequest = Server.CreateObject("ADODB.Stream")
StreamRequest.Type = 1 'adTypeBinary
StreamRequest.Open
uploadedYet = false
End Sub

Private Sub Class_Terminate()
If IsObject(UploadedFiles) Then
UploadedFiles.RemoveAll()
Set UploadedFiles = Nothing
End If
If IsObject(FormElements) Then
FormElements.RemoveAll()
Set FormElements = Nothing
End If
StreamRequest.Close
Set StreamRequest = Nothing
End Sub

Public Property Get Form(sIndex)
Form = ""
If FormElements.Exists(LCase(sIndex)) Then Form = FormElements.Item(LCase(sIndex))
End Property

Public Property Get Files()
Files = UploadedFiles.Items
End Property

'Calls Upload to extract the data from the binary request and then saves the uploaded files
Public Sub Save(path)
Dim streamFile, fileItem

if Right(path, 1) <> "\" then path = path & "/"

if not uploadedYet then Upload

For Each fileItem In UploadedFiles.Items
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = 1
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & fileItem.FileName, 2
streamFile.close
Set streamFile = Nothing
fileItem.Path = path & fileItem.FileName
Next
End Sub

Public Function SaveBinRequest(path) ' For debugging purposes
StreamRequest.SaveToFile path & "\debugStream.bin", 2
End Function

Public Sub DumpData() 'only works if files are plain text
Dim i, aKeys, f
response.write "Form Items:<br>"
aKeys = FormElements.Keys
For i = 0 To FormElements.Count -1 ' Iterate the array
response.write aKeys(i) & " = " & FormElements.Item(aKeys(i)) & "<BR>"
Next
response.write "Uploaded Files:<br>"
For Each f In UploadedFiles.Items
response.write "Name: " & f.FileName & "<br>"
response.write "Type: " & f.ContentType & "<br>"
response.write "Start: " & f.Start & "<br>"
response.write "Size: " & f.Length & "<br>"
Next
End Sub

Private Sub Upload()
Dim nCurPos, nDataBoundPos, nLastSepPos
Dim nPosFile, nPosBound
Dim sFieldName, osPathSep, auxStr

'RFC1867 Tokens
Dim vDataSep
Dim tNewLine, tDoubleQuotes, tTerm, tFilename, tName, tContentDisp, tContentType
tNewLine = Byte2String(Chr(13))
tDoubleQuotes = Byte2String(Chr(34))
tTerm = Byte2String("--")
tFilename = Byte2String("filename=""")
tName = Byte2String("name=""")
tContentDisp = Byte2String("Content-Disposition")
tContentType = Byte2String("Content-Type:")

uploadedYet = true

on error resume next
VarArrayBinRequest = Request.BinaryRead(Request.TotalBytes)
if Err.Number <> 0 then
response.write "<br><br><B>System reported this error:</B><p>"
response.write Err.Description & "<p>"
response.write "The most likely cause for this error is the incorrect setup of AspMaxRequestEntityAllowed in IIS MetaBase. Please see instructions in the <A HREF='http://www.freeaspupload.net/freeaspupload/requirements.asp'>requirements page of freeaspupload.net</A>.<p>"
Exit Sub
end if
on error goto 0 'reset error handling

nCurPos = FindToken(tNewLine,1) 'Note: nCurPos is 1-based (and so is InstrB, MidB, etc)

If nCurPos <= 1 Then Exit Sub

'vDataSep is a separator like -----------------------------21763138716045
vDataSep = MidB(VarArrayBinRequest, 1, nCurPos-1)

'Start of current separator
nDataBoundPos = 1

'Beginning of last line
nLastSepPos = FindToken(vDataSep & tTerm, 1)

Do Until nDataBoundPos = nLastSepPos

nCurPos = SkipToken(tContentDisp, nDataBoundPos)
nCurPos = SkipToken(tName, nCurPos)
sFieldName = ExtractField(tDoubleQuotes, nCurPos)

nPosFile = FindToken(tFilename, nCurPos)
nPosBound = FindToken(vDataSep, nCurPos)

If nPosFile <> 0 And nPosFile < nPosBound Then
Dim oUploadFile
Set oUploadFile = New UploadedFile

nCurPos = SkipToken(tFilename, nCurPos)
auxStr = ExtractField(tDoubleQuotes, nCurPos)
' We are interested only in the name of the file, not the whole path
' Path separator is \ in windows, / in UNIX
' While IE seems to put the whole pathname in the stream, Mozilla seem to
' only put the actual file name, so UNIX paths may be rare. But not impossible.
osPathSep = "\"
if InStr(auxStr, osPathSep) = 0 then osPathSep = "/"
oUploadFile.FileName = Right(auxStr, Len(auxStr)-InStrRev(auxStr, osPathSep))

if (Len(oUploadFile.FileName) > 0) then 'File field not left empty
nCurPos = SkipToken(tContentType, nCurPos)

auxStr = ExtractField(tNewLine, nCurPos)
' NN on UNIX puts things like this in the streaa:
' ?? python py type=?? python application/x-python
oUploadFile.ContentType = Right(auxStr, Len(auxStr)-InStrRev(auxStr, " "))
nCurPos = FindToken(tNewLine, nCurPos) + 4 'skip empty line

oUploadFile.Start = nCurPos-1
oUploadFile.Length = FindToken(vDataSep, nCurPos) - 2 - nCurPos

If oUploadFile.Length > 0 Then UploadedFiles.Add LCase(sFieldName), oUploadFile
End If
Else
Dim nEndOfData
nCurPos = FindToken(tNewLine, nCurPos) + 4 'skip empty line
nEndOfData = FindToken(vDataSep, nCurPos) - 2
If Not FormElements.Exists(LCase(sFieldName)) Then
FormElements.Add LCase(sFieldName), String2Byte(MidB(VarArrayBinRequest, nCurPos, nEndOfData-nCurPos))
else
FormElements.Item(LCase(sFieldName))= FormElements.Item(LCase(sFieldName)) & ", " & String2Byte(MidB(VarArrayBinRequest, nCurPos, nEndOfData-nCurPos))
end if

End If

'Advance to next separator
nDataBoundPos = FindToken(vDataSep, nCurPos)
Loop
StreamRequest.Write(VarArrayBinRequest)
End Sub

Private Function SkipToken(sToken, nStart)
SkipToken = InstrB(nStart, VarArrayBinRequest, sToken)
If SkipToken = 0 then
Response.write "Error in parsing uploaded binary request."
Response.End
end if
SkipToken = SkipToken + LenB(sToken)
End Function

Private Function FindToken(sToken, nStart)
FindToken = InstrB(nStart, VarArrayBinRequest, sToken)
End Function

Private Function ExtractField(sToken, nStart)
Dim nEnd
nEnd = InstrB(nStart, VarArrayBinRequest, sToken)
If nEnd = 0 then
Response.write "Error in parsing uploaded binary request."
Response.End
end if
ExtractField = String2Byte(MidB(VarArrayBinRequest, nStart, nEnd-nStart))
End Function

'String to byte string conversion
Private Function Byte2String(sString)
Dim i
For i = 1 to Len(sString)
Byte2String = Byte2String & ChrB(AscB(Mid(sString,i,1)))
Next
End Function

'Byte string to string conversion
Private Function String2Byte(bsString)
Dim i
String2Byte =""
For i = 1 to LenB(bsString)
String2Byte = String2Byte & Chr(AscB(MidB(bsString,i,1)))
Next
End Function
End Class

Class UploadedFile
Public ContentType
Public Start
Public Length
Public Path
Private nameOfFile

' Need to remove characters that are valid in UNIX, but not in Windows
Public Property Let FileName(fN)
nameOfFile = fN
nameOfFile = SubstNoReg(nameOfFile, "\", "_")
nameOfFile = SubstNoReg(nameOfFile, "/", "_")
nameOfFile = SubstNoReg(nameOfFile, ":", "_")
nameOfFile = SubstNoReg(nameOfFile, "*", "_")
nameOfFile = SubstNoReg(nameOfFile, "?", "_")
nameOfFile = SubstNoReg(nameOfFile, """", "_")
nameOfFile = SubstNoReg(nameOfFile, "<", "_")
nameOfFile = SubstNoReg(nameOfFile, ">", "_")
nameOfFile = SubstNoReg(nameOfFile, "|", "_")
End Property

Public Property Get FileName()
FileName = nameOfFile
End Property

'Public Property Get FileN()ame
End Class


' Does not depend on RegEx, which is not available on older VBScript
' Is not recursive, which means it will not run out of stack space
Function SubstNoReg(initialStr, oldStr, newStr)
Dim currentPos, oldStrPos, skip
If IsNull(initialStr) Or Len(initialStr) = 0 Then
SubstNoReg = ""
ElseIf IsNull(oldStr) Or Len(oldStr) = 0 Then
SubstNoReg = initialStr
Else
If IsNull(newStr) Then newStr = ""
currentPos = 1
oldStrPos = 0
SubstNoReg = ""
skip = Len(oldStr)
Do While currentPos <= Len(initialStr)
oldStrPos = InStr(currentPos, initialStr, oldStr)
If oldStrPos = 0 Then
SubstNoReg = SubstNoReg & Mid(initialStr, currentPos, Len(initialStr) - currentPos + 1)
currentPos = Len(initialStr) + 1
Else
SubstNoReg = SubstNoReg & Mid(initialStr, currentPos, oldStrPos - currentPos) & newStr
currentPos = oldStrPos + skip
End If
Loop
End If
End Function
%>
  #8 (permalink)  
Antiguo 20/06/2008, 09:37
 
Fecha de Ingreso: mayo-2008
Mensajes: 77
Antigüedad: 16 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

Moderadores: siento pegar una respuesta tan larga pero alguien me puede decir como se hace para poner a los mensajes el scroll en el foro?
  #9 (permalink)  
Antiguo 23/06/2008, 01:41
 
Fecha de Ingreso: mayo-2007
Mensajes: 239
Antigüedad: 17 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

acabo leer tu respuesta, pues hasta hoy no trabaje muchas gracias por la ayuda, me pongo ahora mismo a mirar el codigo a ver si lo soluciono, GRACIAS!!
  #10 (permalink)  
Antiguo 23/06/2008, 05:28
 
Fecha de Ingreso: mayo-2008
Mensajes: 77
Antigüedad: 16 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

ese lo hice a la bulla, si te das cuenta esta muy desordenado, pero funciona 100%, para cualquier duda postea, encantado de ayudar.
  #11 (permalink)  
Antiguo 23/06/2008, 08:17
Avatar de JuanRAPerez
Colaborador
 
Fecha de Ingreso: octubre-2003
Mensajes: 2.393
Antigüedad: 21 años, 6 meses
Puntos: 27
Respuesta: problema con Post.Upload

Cita:
Iniciado por piskui Ver Mensaje
Hola tengo un archivo ASP que llama a una funcion de otro archivo ASP, la cual se encarga de subir archivos al servidor (tarea de administrador) el tema es que esa funcion al ir a subir una imagen me da un fallo en esta linea:

Post.Upload RUTA (donde ruta es una carpeta del servidor)
Podria ser tema del servidor de que no tenga permisos para escribir en la carpeta del servidor? y entonces no pueda copiar el archivo en la carpeta¿
a que otras causas puede deberse este problema??
...

gracias un saludo!!!
y el error es?????
__________________
JuanRa Pérez
San Salvador, El Salvador
  #12 (permalink)  
Antiguo 23/06/2008, 09:23
 
Fecha de Ingreso: mayo-2007
Mensajes: 239
Antigüedad: 17 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

el error era que me aparecia un mensaje de error al intentar subir una foto o archivo al servidor, que es lo que hace la funcion upload.
El codigo estuve revisandolo y mas o menos hace lo mismo que el que me pasaste loverpiu, muchas gracias por darme tu codigo de referencia.

El problema esta resuelto y era un tema de servidor, no tenia habilitada la escritura la carpeta donde van los archivos y claro como yo no tengo accesso al servidor porque el tema del servidor lo lleva otro chico que no es de mi empresa ni de mi ciudad....no dependia de mi y yo comiendome el coco para dar con la solución.
Muchas gracias por vuestra ayuda!
  #13 (permalink)  
Antiguo 23/06/2008, 10:31
 
Fecha de Ingreso: mayo-2008
Mensajes: 77
Antigüedad: 16 años, 11 meses
Puntos: 0
Respuesta: problema con Post.Upload

Me alegra haberte servido de ayuda, para lo que necesites aqui estamos
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 07:15.