quiero guardar el binario de una imagen, q tiene el usuario en local,
a una bD mysql, en un campo blob,
lo veo en php y asp net,
pero no en asp
| ||||
![]() El pagina principal donde esta el form:
Código:
La pagina donde recibes los datos y guardas en la base de datos:<!-- 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>
Código:
<% ' 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>Inserts Images into Database</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>
__________________ Solo mi fido del tempo, le parole ed i fatti per prendere le decisioni più importanti della mia vita. // Solo confio en el tiempo, las palabras y los hechos para tomar las decisiones mas importantes de mi vida. Jonatan Lavado |
| ||||
La Libreria:
Código:
<% ' -- Loader.asp -- ' -- version 1.5 ' -- last updated 6/13/2002 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 %>
__________________ Solo mi fido del tempo, le parole ed i fatti per prendere le decisioni più importanti della mia vita. // Solo confio en el tiempo, las palabras y los hechos para tomar las decisiones mas importantes de mi vida. Jonatan Lavado |
| ||||
Analizalo y adaptalo a tus necesidades..
__________________ Solo mi fido del tempo, le parole ed i fatti per prendere le decisioni più importanti della mia vita. // Solo confio en el tiempo, las palabras y los hechos para tomar las decisiones mas importantes de mi vida. Jonatan Lavado |
| ||||
ah... para mostrar la foto no tengo el archivo original, pero en mi caso lo hice asi: <img src="datifoto.asp?id=<%=mivariable%>" > Y esta es la pagina datifoto.asp:
Código:
Si se te hace muy complicado entender el archivo original y no estas apurado, avisame que el fin de semana puedo depurar el codigo de mi pagina y te muestro solo la informacion q necitas ok... espero t sirva de algo, ciao... <% cla = Request.querystring("id") Response.Buffer = True Response.Expires = 0 Set OBJdbConnection = Server.CreateObject("ADODB.Connection") OBJdbConnection.open DSNDB_NAME,SQLSERVER_USER,SQLSERVER_PASSWORD cone= "select e.foto as foto from elencopubblico e where e.progr='"+cla+"'" set DaT= OBJdbConnection.Execute(cone) Response.ContentType = "image/jpeg" Response.BinaryWrite dat("foto") set dat=nothing OBJdbConnection.close %>
__________________ Solo mi fido del tempo, le parole ed i fatti per prendere le decisioni più importanti della mia vita. // Solo confio en el tiempo, las palabras y los hechos para tomar las decisiones mas importantes de mi vida. Jonatan Lavado |
| ||||
encuentro que es mas facil con el xelupload... pero bueno en gustos no hay nada escrito.. saludos
__________________ Haz la guerra en la cama y el amor donde se te de la gana... El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!! |
| ||||
hola, El_Metalick, estoy probando el xelupload y me da un error 800a0046 Permiso denegado, revise los atributos en mi servidor y esta todo ok, esto lo estoy haciendo para un intranet, podrias darme una mano, mi servidor es W2K Pro, gracias :)
__________________ Sigue al indio desnudo... Pero con precaución, atendiendo las señales de transito y comentando todo lo que haces. REM Hay que encontrar el camino de regreso y no siempre es facil.... |
| ||||
si se te deniega el permiso al momento de subir la imagen es porque el directorio al que estas tratando de subirla no tiene los permisos de escritura correspondientes... saludos
__________________ Haz la guerra en la cama y el amor donde se te de la gana... El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!! |