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

subir fotos

Estas en el tema de subir fotos en el foro de ASP Clásico en Foros del Web. Pues eso, que aunque estuve mirando en las faq y si que sale, los links no funcionan , por lo que pongo lo siguiente : ...
  #1 (permalink)  
Antiguo 15/07/2003, 05:00
moncherote
Invitado
 
Mensajes: n/a
Puntos:
Pregunta subir fotos

Pues eso, que aunque estuve mirando en las faq y si que sale, los links no funcionan , por lo que pongo lo siguiente :

Quiero que usuarios de mi pagina rellenen un formulario y que puedan subir con codigo asp fotos a mi sitio web a una carpeta images . No una sino varias , y que al mismo tiempo que me sube las fotos me guarde en la base de datos el contenido del form y el nombre de las fotos para luego mostrarlas yo por la ruta.

Pues eso :-p

  #2 (permalink)  
Antiguo 15/07/2003, 09:04
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
aqui tienes un ejemplo buenisimo y sencillo, ese es el que utilizo actualmente y es super facil. consta de tres archivos...

index.asp

<html>

<head>
<title></title>
</head>

<body>

<form method="POST" enctype="multipart/form-data" action="salvar.asp">
<p><input type="file" name="file" size="20"></p>
<p><input type="submit" value="Enviar" name="B1"></p>
</form>

</body>

</html>



salvar.asp

<!--#include file="Loader.asp"-->
<%
Response.Buffer = True
Dim load
Set load = new Loader
load.initialize
Dim fileData
fileData = load.getFileData("file")
Dim fileName
fileName = LCase(load.getFileName("file"))
Dim filePath
filePath = load.getFilePath("file")
Dim filePathComplete
filePathComplete = load.getFilePathComplete("file")
Dim fileSize
fileSize = load.getFileSize("file")
Dim fileSizeTranslated
fileSizeTranslated = load.getFileSizeTranslated("file")
Dim contentType
contentType = load.getContentType("file")
Dim countElements
countElements = load.Count
Dim nameInput
nameInput = load.getValue("name")
Dim pathToFile
pathToFile = Server.mapPath("upload/") & "\" & fileName
Dim fileUploaded
fileUploaded = load.saveToFile ("file", pathToFile)
Set load = Nothing
%>

<% If fileUploaded = True Then %>
fileName = <%= fileName %><br>
filePath = <%= filePath %><br>
filePathComplete = <%= filePathComplete %><br>
fileSizeTranslated = <%= fileSizeTranslated %><br>
contentType = <%= contentType %><br>
countElements = <%= countElements %><br>
pathToFile = <%= pathToFile %><br>
fileUploaded = <%= fileUploaded %><br>
<% Else %>
No subiste ningun archivo
<% End IF %>



loader.asp


<%

Class Loader
Private dict

Private Sub Class_Initialize
Set dict = Server.CreateObject("Scripting.Dictionary")
End Sub

Private Sub Class_Terminate
If IsObject(intDict) Then
intDict.RemoveAll
Set intDict = Nothing
End If
If IsObject(dict) Then
dict.RemoveAll
Set dict = Nothing
End If
End Sub

Public Property Get Count
Count = dict.Count
End Property

Public Sub Initialize
If Request.TotalBytes > 0 Then
Dim binData
binData = Request.BinaryRead(Request.TotalBytes)
getData binData
End If
End Sub

Public Function getFileData(name)
If dict.Exists(name) Then
getFileData = dict(name).Item("Value")
Else
getFileData = ""
End If
End Function

Public Function getValue(name)
Dim gv
If dict.Exists(name) Then
gv = CStr(dict(name).Item("Value"))

gv = Left(gv,Len(gv)-2)
getValue = gv
Else
getValue = ""
End If
End Function

Public Function saveToFile(name, path)
If dict.Exists(name) Then
Dim temp
temp = dict(name).Item("Value")
Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Dim file
Set file = fso.CreateTextFile(path)
For tPoint = 1 to LenB(temp)
file.Write Chr(AscB(MidB(temp,tPoint,1)))
Next
file.Close
saveToFile = True
Else
saveToFile = False
End If
End Function

Public Function getFileName(name)
If dict.Exists(name) Then
Dim temp, tempPos
temp = dict(name).Item("FileName")
tempPos = 1 + InStrRev(temp, "\")
getFileName = Mid(temp, tempPos)
Else
getFileName = ""
End If
End Function

Public Function getFilePath(name)
If dict.Exists(name) Then
Dim temp, tempPos
temp = dict(name).Item("FileName")
tempPos = InStrRev(temp, "\")
getFilePath = Mid(temp, 1, tempPos)
Else
getFilePath = ""
End If
End Function

Public Function getFilePathComplete(name)
If dict.Exists(name) Then
getFilePathComplete = dict(name).Item("FileName")
Else
getFilePathComplete = ""
End If
End Function

Public Function getFileSize(name)
If dict.Exists(name) Then
getFileSize = LenB(dict(name).Item("Value"))
Else
getFileSize = 0
End If
End Function

Public Function getFileSizeTranslated(name)
If dict.Exists(name) Then
temp = 1 + LenB(dict(name).Item("Value"))
If Len(temp) <= 3 Then
getFileSizeTranslated = temp & " bytes"
ElseIf Len(temp) > 6 Then
temp = FormatNumber(((temp / 1024) / 1024), 2)
getFileSizeTranslated = temp & " megabytes"
Else
temp = FormatNumber((temp / 1024), 2)
getFileSizeTranslated = temp & " kilobytes"
End If
Else
getFileSizeTranslated = ""
End If
End Function

Public Function getContentType(name)
If dict.Exists(name) Then
getContentType = dict(name).Item("ContentType")
Else
getContentType = ""
End If
End Function

Private Sub getData(rawData)
Dim separator
separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)

Dim lenSeparator
lenSeparator = LenB(separator)

Dim currentPos
currentPos = 1
Dim inStrByte
inStrByte = 1
Dim value, mValue
Dim tempValue
tempValue = ""

While inStrByte > 0
inStrByte = InStrB(currentPos, rawData, separator)
mValue = inStrByte - currentPos

If mValue > 1 Then
value = MidB(rawData, currentPos, mValue)

Dim begPos, endPos, midValue, nValue
Dim intDict
Set intDict = Server.CreateObject("Scripting.Dictionary")

begPos = 1 + InStrB(1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))
nValue = endPos

Dim nameN
nameN = MidB(value, begPos, endPos - begPos)

Dim nameValue, isValid
isValid = True

If InStrB(1, value, stringToByte("Content-Type")) > 1 Then

begPos = 1 + InStrB(endPos + 1, value, ChrB(34))
endPos = InStrB(begPos + 1, value, ChrB(34))

If endPos = 0 Then
endPos = begPos + 1
isValid = False
End If

midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "FileName", trim(byteToString(midValue))

begPos = 14 + InStrB(endPos + 1, value, stringToByte("Content-Type:"))
endPos = InStrB(begPos, value, ChrB(13))

midValue = MidB(value, begPos, endPos - begPos)
intDict.Add "ContentType", trim(byteToString(midValue))

begPos = endPos + 4
endPos = LenB(value)

nameValue = MidB(value, begPos, endPos - begPos)
Else
nameValue = trim(byteToString(MidB(value, nValue + 5)))
End If

If isValid = true Then
intDict.Add "Value", nameValue
intDict.Add "Name", nameN

dict.Add byteToString(nameN), intDict
End If
End If

currentPos = lenSeparator + inStrByte
Wend
End Sub

End Class

Private Function stringToByte(toConv)
Dim tempChar
For i = 1 to Len(toConv)
tempChar = Mid(toConv, i, 1)
stringToByte = stringToByte & chrB(AscB(tempChar))
Next
End Function

Private Function byteToString(toConv)
For i = 1 to LenB(toConv)
byteToString = byteToString & chr(AscB(MidB(toConv,i,1)))
Next
End Function
%>




el arhivo loader.asp no lleva ningun codigo html, solo el coidgo que esa alli...


espero te funcione y suerte
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #3 (permalink)  
Antiguo 15/07/2003, 09:14
 
Fecha de Ingreso: marzo-2001
Ubicación: Gran Canaria
Mensajes: 381
Antigüedad: 23 años, 3 meses
Puntos: 2
muy buena la clase Loader , asi te evitas tener que tener instalados componentes de upload en el servidor...






ToKaTa.
__________________

"Si pudieras volver.....¿.lo harias?"

Última edición por ToKaTa; 15/07/2003 a las 09:56
  #4 (permalink)  
Antiguo 15/07/2003, 09:48
moncherote
Invitado
 
Mensajes: n/a
Puntos:
De acuerdo guay!!!

Gracias tio!!!
lo voy a probar, pero seguro que funciona!!
un millon!!
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

SíEste tema le ha gustado a 1 personas (incluyéndote)




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