Foros del Web » Creando para Internet » HTML »

escribir en input type=FILE

Estas en el tema de escribir en input type=FILE en el foro de HTML en Foros del Web. Hola q tal , me gustaria saber si se puede escribir texto en las cajas de texto del tipo file.... gracias y un saludo...
  #1 (permalink)  
Antiguo 29/09/2004, 10:54
 
Fecha de Ingreso: abril-2004
Mensajes: 68
Antigüedad: 20 años
Puntos: 0
escribir en input type=FILE

Hola q tal , me gustaria saber si se puede escribir texto en las cajas de texto del tipo file....

gracias y un saludo
__________________
David
www.crosseros.com
  #2 (permalink)  
Antiguo 29/09/2004, 11:01
 
Fecha de Ingreso: julio-2002
Ubicación: Valparaiso
Mensajes: 152
Antigüedad: 21 años, 9 meses
Puntos: 0
De escribir lo puedes hacer, aunk ese tipo de objeto no esta hecho para eso, para eso estan los de tipo text
Pk la pregunta??? si se puede saber
  #3 (permalink)  
Antiguo 29/09/2004, 11:04
Avatar de monoswim
$moderador{'Esteban'}
 
Fecha de Ingreso: febrero-2002
Ubicación: Buenos Aires - Argentina
Mensajes: 8.762
Antigüedad: 22 años, 2 meses
Puntos: 90
si, claro que puedes escribir, es para escribir la dirección del archivo o bien apretar el boton de examinar para llegar por el navegador archivos de windows.

Código:
<form name="form1" enctype="multipart/form-data" method="post" action="">
  <input type="file" name="file">
</form>
Espero que te sirva, saludos
__________________
Esteban Quintana
  #4 (permalink)  
Antiguo 29/09/2004, 11:16
 
Fecha de Ingreso: abril-2004
Mensajes: 68
Antigüedad: 20 años
Puntos: 0
bueno, veo que no me habeis entendido, tampoco me he explicado, entonces me voy a explicar, tengo un formulario con un input type=text para el titulo, un textarea para la descripcion, y un type=file para subir una imagen, esto es para subir noticias, entonces, al pulsar un boton para ver la vista preliminar, sale todo bien(la imagen no la pongo), pero debajo de donde muestro la vista preliminar vuelvo a poner el formulario por si se quiere hacer algun cambio....con los mismos valores q se han introducido, en el tipo texto y textarea es facil poner los valores, pero en el tipo file no lo consigo.....

espero q me hayais entendido


gracias y un saludo
__________________
David
www.crosseros.com
  #5 (permalink)  
Antiguo 29/09/2004, 11:43
 
Fecha de Ingreso: septiembre-2004
Mensajes: 72
Antigüedad: 19 años, 7 meses
Puntos: 0
Amigo, lo que tu buscas no se puede hacer, yo tambien queria lo mismo y no pude ni utilizando java!!!

Me han dicho por ahi que ese campo typo FILE solo es ReadOnly y por ese motvo no permite que tu le des la ruta al archivo.


Saludos.
__________________
Pablo F. Savino
---------------

Para aficionados a la Simulacion Aerea Virtual ,
visiten:
http://www.cargovirtual.com
  #6 (permalink)  
Antiguo 29/09/2004, 11:51
 
Fecha de Ingreso: abril-2004
Mensajes: 68
Antigüedad: 20 años
Puntos: 0
gracias de todas formas.....pues menuda......!!!!!!!!!! jejejejej....

gracias y un saludo
__________________
David
www.crosseros.com
  #7 (permalink)  
Antiguo 30/09/2004, 11:40
(Desactivado)
 
Fecha de Ingreso: noviembre-2002
Ubicación: Ciudad Autónoma de Buenos Aires
Mensajes: 2.367
Antigüedad: 21 años, 5 meses
Puntos: 317
Hola todos :

dcabrera : se me ocurre que puedes guardar el valor del primer input en una variable, al mostrar el nuevo formulario el file va a estar vacío, pero se puede mostrar en una capa el valor que tenía asignado con la opción de "reaceptar" o cambiarlo-ahora sí- con el file.

saludos

furoya
  #8 (permalink)  
Antiguo 30/09/2004, 14:19
 
Fecha de Ingreso: julio-2002
Ubicación: Valparaiso
Mensajes: 152
Antigüedad: 21 años, 9 meses
Puntos: 0
Si te entiendo bien.. tienes un formulario donde ingresas noticias(Titulo, contenido, imagen), al insertar pasas a otra pagina k te muestar como quedarian lo datos (Previsualizacion) y aparece el mismo form abajo con lo datos para ver si es k quieres modificarlos...
Si es asi podrias usar Asp o Php , le asisgnas los datos a una variable y asi lo puedes ir pasando de pagina en pagina..
Supongo que si estas haciendo un sistema de noticias, estas las guardas en uan Bd.. o me equivoco??
  #9 (permalink)  
Antiguo 30/09/2004, 14:48
 
Fecha de Ingreso: abril-2004
Mensajes: 68
Antigüedad: 20 años
Puntos: 0
hola de nuevo, veo q no me has entendido, lo q tu dices estoy de acuerdo y lo hago....mi pregunta es si puedo al igual que en un tipo=text y un <textarea> asignar un valor, con esto quiero decir, que cuando hago la vista preliminar el formulario tenga el texto que ha introducido el usuario, para no tener q volver a escribirlo, pues bien, sin con estos dos tipos se puede, se puede con un tipo=file???? y de momento parece ser q no se puede....

gracias y un saludo
__________________
David
www.crosseros.com
  #10 (permalink)  
Antiguo 30/09/2004, 23:00
 
Fecha de Ingreso: julio-2002
Ubicación: Valparaiso
Mensajes: 152
Antigüedad: 21 años, 9 meses
Puntos: 0
Ahora creo entendi

Ahora te entendi... aqui te voy a dejar un ejemplo k encontre por ahi ingresa 3 datos y una imagen, el segundo archivo, insert.asp te muestra una pagina de previsualizacion con los datos k ya guardo en la Bd, uno de ellos es la path completa del archivo, solo deberias usar lo de la previsualizacion y dejar la insercion en la Bd para despues cuando el usuario confirme la actualizacion.
Deberas crear la base de datos y la tabla correspondiente, los ultimos 2 asp son para ver la imagen, pero para lo k quieres solo necesitas los 3 primeros...
si quieres me dejas tu correo y te envio los archivos

insert.htm (formulario de ingreso)

<!-- insert.htm -->
<html>
<head>
<title>Inserts Images into Database</title>
<style>
body, input { font-family:verdana,arial; font-size:10pt; }
</style>
</head>
<body>
<p align="center">
<b>Inserting Binary Data into Database</b><br>
<a href="show.asp">To see inserted data click here</a>
</p>

<table border="0" align="center">
<tr>
<form method="POST" enctype="multipart/form-data" action="insert.asp">
<td>First Name :</td><td>
<input type="text" name="fname" size="40"></td>
</tr>
<td>Last Name :</td><td>
<input type="text" name="lname" size="40"></td>
</tr>
<td>Profession :</td><td>
<input type="text" name="profession" size="40">
</td></tr>
<td>File :</td><td>
<input type="file" name="file" size="40"></td></tr>
<td> </td><td>
<input type="submit" value="Submit"></td></tr>
</form>
</tr>
</table>

</body>
</html>

Insert.asp

<!--#include file="loader.asp"-->
<%
Response.Buffer = True

' load object
Dim load
Set load = new Loader

' calling initialize method
load.initialize

' File binary data
Dim fileData
fileData = load.getFileData("file")
' File name
Dim fileName
fileName = LCase(load.getFileName("file"))
' File path
Dim filePath
filePath = load.getFilePath("file")
' File path complete
Dim filePathComplete
filePathComplete = load.getFilePathComplete("file")
' File size
Dim fileSize
fileSize = load.getFileSize("file")
' File size translated
Dim fileSizeTranslated
fileSizeTranslated = load.getFileSizeTranslated("file")
' Content Type
Dim contentType
contentType = load.getContentType("file")
' No. of Form elements
Dim countElements
countElements = load.Count
' Value of text input field "fname"
Dim fnameInput
fnameInput = load.getValue("fname")
' Value of text input field "lname"
Dim lnameInput
lnameInput = load.getValue("lname")
' Value of text input field "profession"
Dim profession
profession = load.getValue("profession")

' destroying load object
Set load = Nothing
%>

<html>
<head>
<title>Insertando Imagenes en una Base de Datos</title>
<style>
body, input, td { font-family:verdana,arial; font-size:10pt; }
</style>
</head>
<body>
<p align="center">
<b>Inserting Binary Data into Database</b><br>
<a href="show.asp">To see inserted data click here</a>
</p>

<table width="700" border="1" align="center">
<tr>
<td>File Name</td><td><%= fileName %></td>
</tr><tr>
<td>File Path</td><td><%= filePath %></td>
</tr><tr>
<td>File Path Complete</td><td><%= filePathComplete %></td>
</tr><tr>
<td>File Size</td><td><%= fileSize %></td>
</tr><tr>
<td>File Size Translated</td><td><%= fileSizeTranslated %></td>
</tr><tr>
<td>Content Type</td><td><%= contentType %></td>
</tr><tr>
<td>No. of Form Elements</td><td><%= countElements %></td>
</tr><tr>
<td>First Name</td><td><%= fnameInput %></td>
</tr><tr>
<td>Last Name</td><td><%= lnameInput %></td>
</tr>
<tr>
<td>Profession</td><td><%= profession %></td>
</tr>
</table><br><br>

<p style="padding-left:220;">
<%= fileName %> data received ...<br>
<%
' Checking to make sure if file was uploaded
If fileSize > 0 Then

' Connection string
Dim connStr
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="
connStr = connStr & Server.MapPath("FileDB.mdb")

' Recordset object
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")

rs.Open "Files", connStr, 2, 2

' Adding data
rs.AddNew
rs("File Name") = fileName
rs("File Size") = fileSize
rs("File Data").AppendChunk fileData
rs("Content Type") = contentType
rs("First Name") = fnameInput
rs("Last Name") = lnameInput
rs("Profession") = profession
rs.Update

rs.Close
Set rs = Nothing

Response.Write "<font color=""green"">File was successfully uploaded..."
Response.Write "</font>"
Else
Response.Write "<font color=""brown"">No file was selected for uploading"
Response.Write "...</font>"
End If


If Err.number <> 0 Then
Response.Write "<br><font color=""red"">Something went wrong..."
Response.Write "</font>"
End If
%>
</p>

<br>
<table border="0" align="center">
<tr>
<form method="POST" enctype="multipart/form-data" action="insert.asp">
<td>First Name :</td><td>
<input type="text" name="fname" size="40" ></td>
</tr>
<td>Last Name :</td><td>
<input type="text" name="lname" size="40" ></td>
</tr>
<td>Profession :</td><td>
<input type="text" name="profession" size="40" ></td>
</tr>
<td>File :</td><td>
<input type="file" name="file" size="40"></td>
</tr>
<td> </td><td>
<input type="submit" value="Submit"></td>
</tr>
</form>
</tr>
</table>

</body>
</html>
  #11 (permalink)  
Antiguo 30/09/2004, 23:02
 
Fecha de Ingreso: julio-2002
Ubicación: Valparaiso
Mensajes: 152
Antigüedad: 21 años, 9 meses
Puntos: 0
Aca Continua

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
%>

show.asp

<%

Response.Buffer = True

' Connection String
Dim connStr
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("FileDB.mdb")
%>
<html>
<head>
<title>Inserts Images into Database</title>
<style>
body, input, td { font-family:verdana,arial; font-size:10pt; }
</style>
</head>
<body>
<p align="center">
<b>Showing Binary Data from the Database</b><br>
<a href="insert.htm">To insert data click here</a>
</p>

<table width="700" border="1" align="center">
<%
' Recordset Object
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")

' opening connection
rs.Open "select [ID],[File Name],[File Size],[Content Type],[First Name]," & _
"[Last Name],[Profession] from Files order by [ID] desc", connStr, 3, 4

If Not rs.EOF Then
Response.Write "<tr><td colspan=""7"" align=""center""><i>"
Response.Write "No. of records : " & rs.RecordCount
Response.Write ", Table : Files</i><br>"
Response.Write "</td></tr>"

While Not rs.EOF
Response.Write "<tr><td>"
Response.Write rs("ID") & "</td><td>"
Response.Write "<a href=""file.asp?ID=" & rs("ID") & """>"
Response.Write rs("File Name") & "</a></td><td>"
Response.Write rs("File Size") & "</td><td>"
Response.Write rs("Content Type") & "</td><td>"
Response.Write rs("First Name") & "</td><td>"
Response.Write rs("Last Name") & "</td><td>"
Response.Write rs("Profession")
Response.Write "</td></tr>"
rs.MoveNext
Wend
Else
Response.Write "No Record Found"
End If

rs.Close
Set rs = Nothing
%>
</table>
</body>
</html>

file.asp

<%

Response.Buffer = True

' ID of the file to retrieve
Dim ID
ID = Request("ID")

If Len(ID) < 1 Then
ID = 7
End If

' Connection String
Dim connStr
connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("FileDB.mdb")

' Recordset Object
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")

' opening connection
rs.Open "select [File Data],[Content Type] from Files where ID = " & _
ID, connStr, 2, 4

If Not rs.EOF Then
Response.ContentType = rs("Content Type")
Response.BinaryWrite rs("File Data")
End If


rs.Close
Set rs = Nothing
%>
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:57.