944,146 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Marked Solved
  • Views: 7793
  • ASP RSS
May 25th, 2006
0

File Upload in MySQL Database with ASP

Expand Post »
Hi Everybody!

How to upload a image / pdf file in mysql table blob column with
ASP

pls help me

HemantK
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
HemantK is offline Offline
4 posts
since May 2006
May 28th, 2006
0

Re: File Upload in MySQL Database with ASP

try this one, if i understand well what you want:

Quote ...
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public Sub Addfile(ByVal sender As Object, ByVal e As EventArgs)
UploadFile(1, "test", 123, "c:\myfile.jpg")
End Sub

Public Shared Sub UploadFile(ByVal file_id As Integer, ByVal file_name As String, ByVal file_size As Integer, ByVal file_path As String)

Dim Conn As Data.Odbc.OdbcConnection = New Data.Odbc.OdbcConnection("dsn=mydatabase")
Conn.Open()

Dim command As Data.Odbc.OdbcCommand = New Data.Odbc.OdbcCommand("INSERT INTO `files` set file_name=?, file_size=?, file=?")

Dim file() As Byte = GetFile(file_path)

command.Parameters.Add("?", Data.Odbc.OdbcType.VarChar).Value = file_name
command.Parameters.Add("?", Data.Odbc.OdbcType.Int).Value = file_size
command.Parameters.Add("?", Data.Odbc.OdbcType.Binary).Value = file
command.Connection = Conn
command.ExecuteNonQuery()

Conn.Close()
End Sub

Public Shared Function GetFile(ByVal file_Path As String) As Byte()
Dim stream As System.IO.FileStream = New System.IO.FileStream(file_Path, IO.FileMode.Open, IO.FileAccess.Read)
Dim reader As System.IO.BinaryReader = New System.IO.BinaryReader(stream)
Dim file() As Byte = reader.ReadBytes(stream.Length)
reader.Close()
stream.Close()
Return file
End Function

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="addfile"/>
</div>
</form>
</body>
</html>
Reputation Points: 10
Solved Threads: 4
Newbie Poster
sosco is offline Offline
24 posts
since May 2006
May 29th, 2006
0

Re: File Upload in MySQL Database with ASP

Hi !

Thanks for quick reply and solution.

I have also worked out the problem on the same line

thanks once again

HemantK
Reputation Points: 10
Solved Threads: 0
Newbie Poster
HemantK is offline Offline
4 posts
since May 2006
May 29th, 2006
0

Re: File Upload in MySQL Database with ASP

you are welcom
Reputation Points: 10
Solved Threads: 4
Newbie Poster
sosco is offline Offline
24 posts
since May 2006
May 29th, 2006
0

Re: File Upload in MySQL Database with ASP

*welcome
Reputation Points: 10
Solved Threads: 4
Newbie Poster
sosco is offline Offline
24 posts
since May 2006
Dec 13th, 2007
0

Re: File Upload in MySQL Database with ASP

Hi,

I am new to ASP and I am trying to upload .PDF files into MySQL. Can you please tell me if this can be applied to VBScript instead of VB? Or If you tell me how to make IIS to accept this VB Code. I do not have VB on my server.

Thanks
Zhk
Last edited by zhk; Dec 13th, 2007 at 10:53 am.
zhk
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zhk is offline Offline
4 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Will this work
Next Thread in ASP Forum Timeline: ASP XML - Help Needed ?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC