Los Foros de ASPTutor.com
Home | Perfil | Registrarse | Temas Activos | Miembros | Buscar | FAQ
Usuario:
Password:
 Todos los Foros
 ASP
 Añadir ruta imagen en bd
 Foro Bloqueado  Tema Bloqueado


Autor Temas
Daidass
Starting Member

España
10 Posts
Mensajes - 06 Mar 2006 :  12:59:36  Ver Perfil  Enviar Email
Hola a todos!
Me han pasado una página llena de código que no es mío que tengo que retocar y encima que soy novata y el código no es mío pues me entero de poco. A ver si me podéis ayudar.

La página es un formulario para añadir una noticia en la base de datos, en la cual tengo que añadir una imagen, ahora mismo tiene un examinar para añadir una imagen en la noticia y lo que he añadido debajo del examinar es otro campo para que si la imagen ya esta en el servidor poner el nombre de la imagen ahí y ya está.

Si el código fuera mío pondría algo así:

if count >0 then
For Each File in Upload.Files
ruta ="images/noticias/"& File.FileName
next
else
ruta=ftp
end if
conn.execute=.....

Pero para este código no tengo ni idea de como puedo mandarle esa orden ni donde la tengo que poner.
Este es el código de la página, lo pongo todo porque no se que trozo sería el que habria que retocar.
____________________________________________

Sub BuildUploadRequest(RequestBin)
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
if PosEnd = 0 then
Response.Write "<b>Form was submitted with no ENCTYPE=""multipart/form-data""</b><br>"
Response.Write "Please correct the form attributes and try again."
Response.End
end if
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
'Test if object is of file type
If PosFile<>0 AND (PosFile<PosBound) Then
'Get Filename, content-type and content of file
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
FileName = Mid(FileName,InStrRev(FileName,"\")+1)
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
'Add content-type to dictionary object
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = FileName
ValueBeg = PosBeg-1
ValueLen = PosEnd-Posbeg
Else
'Get content of object
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
ValueBeg = 0
ValueEnd = 0
End If
'Add content to dictionary object
UploadControl.Add "Value" , Value
UploadControl.Add "ValueBeg" , ValueBeg
UploadControl.Add "ValueLen" , ValueLen
'Add dictionary object to main dictionary
UploadRequest.Add name, UploadControl
'Loop to next object
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub

'String to byte string conversion
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function

'Byte string to string conversion
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function

Function UploadFormRequest(name)
on error resume next
if UploadRequest.Item(name) then
UploadFormRequest = UploadRequest.Item(name).Item("Value")
end if
End Function

'Process the upload
UploadQueryString = Replace(Request.QueryString,"GP_upload=true","")
if mid(UploadQueryString,1,1) = "&" then
UploadQueryString = Mid(UploadQueryString,2)
end if

GP_uploadAction = CStr(Request.ServerVariables("URL")) & "?GP_upload=true"
If (Request.QueryString <> "") Then
if UploadQueryString <> "" then
GP_uploadAction = GP_uploadAction & "&" & UploadQueryString
end if
End If

If (CStr(Request.QueryString("GP_upload")) <> "") Then
GP_redirectPage = ""
If (GP_redirectPage = "") Then
GP_redirectPage = CStr(Request.ServerVariables("URL"))
end if

RequestBin = Request.BinaryRead(Request.TotalBytes)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin

GP_keys = UploadRequest.Keys
for GP_i = 0 to UploadRequest.Count - 1
GP_curKey = GP_keys(GP_i)
'Save all uploaded files
if UploadRequest.Item(GP_curKey).Item("FileName") <> "" then
GP_value = UploadRequest.Item(GP_curKey).Item("Value")
GP_valueBeg = UploadRequest.Item(GP_curKey).Item("ValueBeg")
GP_valueLen = UploadRequest.Item(GP_curKey).Item("ValueLen")

if GP_valueLen = 0 then
Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "<br>"
Response.Write "File does not exists or is empty.<br>"
Response.Write "Please correct and <A HREF=""javascript:history.back(1)"">try again</a>"
response.End
end if

'Create a Stream instance
Dim GP_strm1, GP_strm2
Set GP_strm1 = Server.CreateObject("ADODB.Stream")
Set GP_strm2 = Server.CreateObject("ADODB.Stream")

'Open the stream
GP_strm1.Open
GP_strm1.Type = 1 'Binary
GP_strm2.Open
GP_strm2.Type = 1 'Binary

GP_strm1.Write RequestBin
GP_strm1.Position = GP_ValueBeg
GP_strm1.CopyTo GP_strm2,GP_ValueLen

'Create and Write to a File
GP_curPath = Request.ServerVariables("PATH_INFO")
GP_curPath = Trim(Mid(GP_curPath,1,InStrRev(GP_curPath,"/")) & "../images/noticies")
if Mid(GP_curPath,Len(GP_curPath),1) <> "/" then
GP_curPath = GP_curPath & "/"
end if
on error resume next
GP_strm2.SaveToFile Trim(Server.mappath(GP_curPath))& "\" & UploadRequest.Item(GP_curKey).Item("FileName"),2
if err then
Response.Write "<B>An error has occured saving uploaded file!</B><br><br>"
Response.Write "Filename: " & Trim(GP_curPath) & UploadRequest.Item(GP_curKey).Item("FileName") & "<br>"
Response.Write "Maybe the destination directory does not exist, or you don't have write permission.<br>"
Response.Write "Please correct and <A HREF=""javascript:history.back(1)"">try again</a>"
err.clear
response.End
end if
end if
next

'*** GP NO REDIRECT
end if
if UploadQueryString <> "" then
UploadQueryString = UploadQueryString & "&GP_upload=true"
else
UploadQueryString = "GP_upload=true"
end if

%>
<%
' *** Edit Operations: (Modified for File Upload) declare variables

MM_editAction = CStr(Request.ServerVariables("URL")) 'MM_editAction = CStr(Request("URL"))
If (UploadQueryString <> "") Then
MM_editAction = MM_editAction & "?" & UploadQueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: (Modified for File Upload) set variables

If (CStr(UploadFormRequest("MM_insert")) <> "") Then

MM_editConnection = MM_BCN_STRING
MM_editTable = "NOTICIES"
MM_editRedirectUrl = "LISNOBCN.ASP"
MM_fieldsStr = "TITULAR|value|RESUM|value|texte|value|file|value|DATA|value"
MM_columnsStr = "TITULAR|',none,''|RESUM|',none,''|TEXTE|',none,''|IMATGE|',none,''|DATA|#,none,NULL"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(i+1) = CStr(UploadFormRequest(MM_fields(i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And UploadQueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And UploadQueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & UploadQueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & UploadQueryString
End If
End If

End If
%>
<%
' *** Insert Record: (Modified for File Upload) construct a sql insert statement and execute it

If (CStr(UploadFormRequest("MM_insert")) <> "") Then

' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For i = LBound(MM_fields) To UBound(MM_fields) Step 2
FormVal = MM_fields(i+1)
MM_typeArray = Split(MM_columns(i+1),",")
Delim = MM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = MM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = MM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
ElseIf (Delim = "'") Then ' escape quotes
FormVal = "'" & Replace(FormVal,"'","''") & "'"
Else
FormVal = Delim + FormVal + Delim
End If
End If
If (i <> LBound(MM_fields)) Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End if
MM_tableValues = MM_tableValues & MM_columns(i)
MM_dbValues = MM_dbValues & FormVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

If (Not MM_abortEdit) Then
' execute the update
Set conn = Server.CreateObject("adodb.connection")
conn.open strCon
set rs3=server.createobject ("adodb.recordset")
sqlrs = MM_editQuery
rs3.open sqlrs,conn,1,2
If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
rs3.update

End If

rs3.close
set rs3=nothing
End If

End If
%>
<form name="form1" method="POST" action="<%=MM_editAction%>" enctype="multipart/form-data" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG');return document.MM_returnValue">
<table width="100%" border="0" height="205" class="unnamed8">
<tr>
<td width="14%">IMATGE</td>
<td colspan="2">
<input type="file" name="file"> <br>
</td>
</tr>
<tr>
<td>Ruta de imagen en ftp:</td>
<td colspan="7" valign="top" bgcolor="f5f2e6"><input name="ftp" type="text" class="txt" id="ftp" size="50">
</td>
</tr>
<tr>
<td colspan="3">
<input type='submit' value="Introduir notícia" name="submit">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="true">
</form>

Gracias de antemano.

jbarra
Junior Member

Chile
192 Posts
Posted - 06 Mar 2006 :  20:09:51  Ver perfil  Enviar e-mail
Deseas ver si el archivo existe en la carpeta y mostrarla.....es lo que entiendo....esto te puede servir

Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")

miArchivo = ="images/noticias/" & nombre_archivo
If (fso.FileExists(miArchivo)) Then
response.write "archivo existe"
response.write "<img src='images/noticias/" & miArchivo & " border=0>"
end if

Inicio Pagina

Daidass
Starting Member

España
10 Posts
Posted - 07 Mar 2006 :  10:29:52  Ver perfil  Enviar e-mail
Hola!
No es eso lo que quería decir, alomejor no me he expresado bien.
Lo que quiero hacer es tener dos maneras diferentes de añadir una imagen en un campo de la bd. Que pueda añadir la imagen haciendo examinar o bien añadiendo el nombre de la imagen (que ésta ya estará en su correspondiente carpeta en el servidor) en el campo llamado ftp. Resumiendo, que pueda añadir una imagen o bien de una manera o de otra.

Inicio Pagina

   
 Foro Bloqueado  Tema Bloqueado
Ir a:
Los Foros de ASPTutor.com Los Foros de ASPTutor.com
Ir al principio de la Página

 Imprimir Tema
 

Descargas de manuales¦ Ejemplos de código ¦ Artículos mas visitados ¦ Envía tu articulo ¦ Foros ¦
  Libro de visitas ¦Crea un enlace con ASPTutor 
 

    © 2001-Hasta hoy  Pedro Rufo Martín  contactar