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

duda con imagen que subo al server

Estas en el tema de duda con imagen que subo al server en el foro de ASP Clásico en Foros del Web. hola amigos tengo el siguiente codigo para subir una imagen al servidor upload.asp Cita: Class FileUploader Public Files Private mcolFormElem Private Sub Class_Initialize() Set Files ...
  #1 (permalink)  
Antiguo 29/09/2006, 15:20
Avatar de mc_quake  
Fecha de Ingreso: enero-2006
Ubicación: www.ecocargo.cl
Mensajes: 683
Antigüedad: 18 años, 5 meses
Puntos: 8
duda con imagen que subo al server

hola amigos tengo el siguiente codigo para subir una imagen al servidor

upload.asp
Cita:
Class FileUploader
Public Files
Private mcolFormElem

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

Private Sub Class_Terminate()
If IsObject(Files) Then
Files.RemoveAll()
Set Files = Nothing
End If
If IsObject(mcolFormElem) Then
mcolFormElem.RemoveAll()
Set mcolFormElem = Nothing
End If
End Sub

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

Public Default Sub Upload()
Dim biData, sInputName
Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
Dim nPosFile, nPosBound

biData = Request.BinaryRead(Request.TotalBytes)
nPosBegin = 1
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))

If (nPosEnd-nPosBegin) <= 0 Then Exit Sub

vDataBounds = MidB(biData, nPosBegin, nPosEnd-nPosBegin)
nDataBoundPos = InstrB(1, biData, vDataBounds)

Do Until nDataBoundPos = InstrB(biData, vDataBounds & CByteString("--"))

nPos = InstrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
nPos = InstrB(nPos, biData, CByteString("name="))
nPosBegin = nPos + 6
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
nPosFile = InstrB(nDataBoundPos, biData, CByteString("filename="))
nPosBound = InstrB(nPosEnd, biData, vDataBounds)

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

nPosBegin = nPosFile + 10
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(34)))
sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
oUploadFile.FileName = Right(sFileName, Len(sFileName)-InStrRev(sFileName, "\"))

nPos = InstrB(nPosEnd, biData, CByteString("Content-Type:"))
nPosBegin = nPos + 14
nPosEnd = InstrB(nPosBegin, biData, CByteString(Chr(13)))

oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))

nPosBegin = nPosEnd+4
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd-nPosBegin)

If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
Else
nPos = InstrB(nPos, biData, CByteString(Chr(13)))
nPosBegin = nPos + 4
nPosEnd = InstrB(nPosBegin, biData, vDataBounds) - 2
If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd-nPosBegin))
End If

nDataBoundPos = InstrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
Loop
End Sub

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

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

Class UploadedFile
Public ContentType
Public FileName
Public FileData

Public Property Get FileSize()
FileSize = LenB(FileData)
End Property

Public Sub SaveToDisk(sPath)
Dim oFS, oFile
Dim nIndex

If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"

Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub

Set oFile = oFS.CreateTextFile(sPath & FileName, True)

For nIndex = 1 to LenB(FileData)
oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
Next

oFile.Close
End Sub

Public Sub SaveToDatabase(ByRef oField)
If LenB(FileData) = 0 Then Exit Sub

If IsObject(oField) Then
oField.AppendChunk FileData
End If
End Sub

End Class
%>
__________________
Mc_Quake

Para ayudar en lo que se pueda:Zzz:
  #2 (permalink)  
Antiguo 29/09/2006, 15:20
Avatar de mc_quake  
Fecha de Ingreso: enero-2006
Ubicación: www.ecocargo.cl
Mensajes: 683
Antigüedad: 18 años, 5 meses
Puntos: 8
y aca esta el formulario donde subo la imagen ( formulario)

Cita:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%if not session("AdminOk")="true" then response.Redirect "login.asp" %>
<!--#Include file="cn.asp"-->
<!--#include File="upload.asp"-->

<%
dim productname
dim price
dim category
dim details
dim filename

dim msg
Set Uploader = New FileUploader
Uploader.Upload()


if Uploader.Form("submit")<>"" then
productname = Uploader.Form("name")
price = Uploader.Form("Price")
category = Uploader.Form("Category")
details = Uploader.Form("details")
call SaveRecord()
End if

if request.QueryString("id")<>"" then
call GetRecord()
End if


Sub SaveRecord()

dim rs
dim cn

set cn = server.CreateObject("Adodb.Connection")
set rs = server.CreateObject("Adodb.Recordset")

cn.Open conn

if Uploader.Files.count <> 0 then
File = Uploader.Files.Items()
File(0).SavetoDisk Server.MapPath("images\products")
filename = File(0).Filename
else
filename = ""
End if


if Uploader.Form("id")="" then
rs.open "Select * From Products",cn,2,3
rs.addnew
rs.fields("productname") = productname
rs.fields("price") = price
if filename <>"" then rs.fields("image") = filename
rs.fields("details") = details
rs.fields("categoryid") = category
rs.update
msg = "Product Record is saved"
saved = true
else
rs.open "Select * From Products Where ProductID=" & Uploader.Form("id"),cn,2,3
rs.fields("productname") = productname
rs.fields("price") = price
rs.fields("details") = details
rs.fields("categoryid") = category
if filename <>"" then rs.fields("image") = filename
rs.update
msg = "Product Record is updated"
saved = true
End if


rs.close
cn.close
set rs = nothing
set cn = nothing

End Sub


Sub GetRecord()

dim rs
dim cn

set cn = server.CreateObject("Adodb.Connection")
set rs = server.CreateObject("Adodb.Recordset")

cn.Open conn
rs.open "Select * From Products Where ProductID=" & request.QueryString("id"),cn
if not rs.eof then
productname = rs.fields("productname")
price = rs.fields("price")
details = rs.fields("details")
category = rs.fields("categoryid")
filename = rs.fields("image")
End If
rs.close
cn.close
set rs = nothing
set cn = nothing
msg = "Product Record is loaded."
End Sub

%>

<html>
<head>
<title>Admin</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
<p align="center"><font face="Georgia, Times New Roman, Times, serif">Administracion
de Catalogo</font></p>
<p align="center"> <font color="#FF0000"><%= msg%> </font></p>
<form action="" method="post" enctype="multipart/form-data" name="form1">
<table width="56%" height="237" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#CCCCCC">
<tr>
<td height="23" colspan="2" bgcolor="#CCCCCC"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Agregar
Nuevo Producto</strong></font></td>
</tr>
<tr>
<td height="23">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="37%" height="23"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Nombre
Producto </font></td>
<td width="63%"><input name="name" type="text" id="name3" value="<%=productname%>">
</td>
</tr>
<tr>
<td height="26"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Precio</font></td>
<td><input name="price" type="text" id="name" value="<%=price%>"></td>
</tr>
<tr>
<td height="26"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Categoria</font></td>
<td><select name="category" id="category">
<%
dim rs1
dim cn1
set cn1 = server.CreateObject("Adodb.Connection")
set rs1 = server.CreateObject("Adodb.Recordset")
cn1.Open conn
rs1.open "Select * From ProductCategories",cn1
%>
<option value="0" selected >Select</option>
<option value="0" >-</option>
<%if not rs1.eof then
while not rs1.eof%>
<option value="<%=rs1.fields("CategoryID")%>" <%if CLng(Category)=rs1.fields("CategoryID") then response.Write("Selected")%>><%=rs1.fields("Catego ryName")%></option>
<%
rs1.movenext
wend
end if
%>
</select> </td>
</tr>
<tr>
<td height="26" valign="top"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Imagen</font></td>
<td><input type="file" name="file">
<font color="#FF0000"><%= filename%></font></td>
</tr>
<tr>
<td height="26" valign="top"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Detalles</font></td>
<td><textarea name="details" cols="40" rows="5" id="name2"><%=details%></textarea></td>
</tr>
<tr>
<td height="26">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="26">&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset">
</td>
</tr>
</table>
<input name="id" type="hidden" id="id" value="<%=request.querystring("id")%>">
</form>
<p>&nbsp; </p>
<p><a href="listproducts.asp">View </a></p>
<p>&nbsp;</p>
<p>Back to <a href="admin.asp">Main</a></p>
</body>
</html>
mi pregunta es la siguiente cmo le añado a este codigo para que me muestre solo las imagenes jpg y gif

y que ademas me cree una miniatura de la imagen que voy a subir

si alguien me puede ayudar con alguna de estas dos dudas se los agradeceria ya que busque en el foro pero no encontre nada que me dejace muy claro
__________________
Mc_Quake

Para ayudar en lo que se pueda:Zzz:
  #3 (permalink)  
Antiguo 02/10/2006, 15:56
Avatar de mc_quake  
Fecha de Ingreso: enero-2006
Ubicación: www.ecocargo.cl
Mensajes: 683
Antigüedad: 18 años, 5 meses
Puntos: 8
bueno aca va de nuevo mas corto necesito saber como subo solo imagenes a mi bçase de datos y como puedo crear una imagen pequeña de la que subo y agregarla a mi base de datos
__________________
Mc_Quake

Para ayudar en lo que se pueda:Zzz:
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 01:32.