I am trying to create a database-driven photo gallery for a friend with an
admin form to upload images... I can upload a file to the web server, but I
want to store the image in a database and I want to resize the image before
I save it... How do I take the uploaded .jpg and shrink it to a thumbnail?
How do I pass the uploaded .jpg to a stored procedure that will store the
image as an image datatype in SQL Server 2000? I'm developing this without
Visual Studio.
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
End Sub
Sub Button_Click(S as Object, E as EventArgs)
fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho
togallery\NewFile.jpg")
End Sub
</script>
<html>
<head>
<title>Image Upload</title>
</head>
<body>
<form id="frmUpload" method="post" runat="server"
enctype="multipart/form-data">
<input type="file" id="fsoUploadFile" runat="server"><br/>
<asp:button Text="Upload File" OnClick="Button_Click" runat="server"/>
</form>
</body>
</html> 5 3233
Here's an article I wrote that describes how to upload images into a
database and get them back out again. http://steve.orr.net/content/asp200307so_f.asp
Also, here's an image resize routine I wrote:
/*shrink the image proportionately so that neither height nor width is more
than [NewSize] pixels*/
public Image ShrinkImage(Bitmap bmp, int NewSize)
{
double NewWidth;
double NewHeight;
double ShrinkPercent;
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
if (bmp.Width>bmp.Height)
{
NewWidth=NewSize;
ShrinkPercent=(NewWidth/bmp.Width)*100;
NewHeight=(ShrinkPercent/100)*bmp.Height;
}
else
{
NewHeight=NewSize;
ShrinkPercent=(NewHeight/bmp.Height)*100;
NewWidth=(ShrinkPercent/100)*bmp.Width;
}
System.Drawing.Image myShrunkenImage =
bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero);
return myShrunkenImage;
}
public bool ThumbnailCallback(){return false;}
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://Steve.Orr.net
"bob garbados" <bo**************************@yahoo.com> wrote in message
news:10*************@corp.supernews.com... I am trying to create a database-driven photo gallery for a friend with an admin form to upload images... I can upload a file to the web server, but I want to store the image in a database and I want to resize the image before I save it... How do I take the uploaded .jpg and shrink it to a thumbnail? How do I pass the uploaded .jpg to a stored procedure that will store the image as an image datatype in SQL Server 2000? I'm developing this without Visual Studio.
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs) End Sub
Sub Button_Click(S as Object, E as EventArgs)
fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho togallery\NewFile.jpg") End Sub
</script> <html> <head> <title>Image Upload</title> </head> <body> <form id="frmUpload" method="post" runat="server" enctype="multipart/form-data"> <input type="file" id="fsoUploadFile" runat="server"><br/> <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/> </form> </body> </html>
Thanks Steve. I actually found your article and used it as a guide to write
my code for uploading the image to the database. I'm working on retreiving
the images now and the resize routine looks great, I'll implement that once
everything else is working.
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:u6*************@TK2MSFTNGP11.phx.gbl... Here's an article I wrote that describes how to upload images into a database and get them back out again. http://steve.orr.net/content/asp200307so_f.asp
Also, here's an image resize routine I wrote:
/*shrink the image proportionately so that neither height nor width is
more than [NewSize] pixels*/
public Image ShrinkImage(Bitmap bmp, int NewSize)
{
double NewWidth;
double NewHeight;
double ShrinkPercent;
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
if (bmp.Width>bmp.Height)
{
NewWidth=NewSize;
ShrinkPercent=(NewWidth/bmp.Width)*100;
NewHeight=(ShrinkPercent/100)*bmp.Height;
}
else
{
NewHeight=NewSize;
ShrinkPercent=(NewHeight/bmp.Height)*100;
NewWidth=(ShrinkPercent/100)*bmp.Width;
}
System.Drawing.Image myShrunkenImage =
bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero); return myShrunkenImage;
}
public bool ThumbnailCallback(){return false;}
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "bob garbados" <bo**************************@yahoo.com> wrote in message news:10*************@corp.supernews.com...I am trying to create a database-driven photo gallery for a friend with
an admin form to upload images... I can upload a file to the web server,
but I want to store the image in a database and I want to resize the image before I save it... How do I take the uploaded .jpg and shrink it to a
thumbnail? How do I pass the uploaded .jpg to a stored procedure that will store
the image as an image datatype in SQL Server 2000? I'm developing this without Visual Studio.
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs) End Sub
Sub Button_Click(S as Object, E as EventArgs)
fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho togallery\NewFile.jpg") End Sub
</script> <html> <head> <title>Image Upload</title> </head> <body> <form id="frmUpload" method="post" runat="server" enctype="multipart/form-data"> <input type="file" id="fsoUploadFile" runat="server"><br/> <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/> </form> </body> </html>
Steve,
I can save the image in the database, but I can't retrieve it. Here's my
code:
Dim con as SqlConnection
Dim strConnectionString as String
strConnectionString = ConfigurationSettings.AppSettings("connection")
con= New SqlConnection(strConnectionString)
Dim dr As System.Data.SqlClient.SqlDataReader
Dim cmdGetPhoto as new SqlCommand("usp_GetPhotos", con)
con.Open()
dr = cmdGetPhoto.ExecuteReader
If dr.Read Then
Response.Write("Photo is here...")
Response.Write("Photo Name: " & dr("PhotoTitle") & "<br/>")
Response.ContentType = dr("PhotoThumbContentType").ToString
Response.OutputStream.Write(CType(dr("PhotoThumb") , Byte()), 0,
CInt(dr("PhotoThumbSize")))
Response.AddHeader("Content-Disposition", dr("PhotoTitle").ToString())
Else
Response.Write("File Not Found.")
End If
'close down the connection
con.Close()
I stepped through the code and it executes the correct lines of code, but
doesn't write anything and the image doesn't show up. What does the
'inherits="CIT.ViewAttachment"' line in your code do?
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:u6*************@TK2MSFTNGP11.phx.gbl... Here's an article I wrote that describes how to upload images into a database and get them back out again. http://steve.orr.net/content/asp200307so_f.asp
Also, here's an image resize routine I wrote:
/*shrink the image proportionately so that neither height nor width is
more than [NewSize] pixels*/
public Image ShrinkImage(Bitmap bmp, int NewSize)
{
double NewWidth;
double NewHeight;
double ShrinkPercent;
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
if (bmp.Width>bmp.Height)
{
NewWidth=NewSize;
ShrinkPercent=(NewWidth/bmp.Width)*100;
NewHeight=(ShrinkPercent/100)*bmp.Height;
}
else
{
NewHeight=NewSize;
ShrinkPercent=(NewHeight/bmp.Height)*100;
NewWidth=(ShrinkPercent/100)*bmp.Width;
}
System.Drawing.Image myShrunkenImage =
bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero); return myShrunkenImage;
}
public bool ThumbnailCallback(){return false;}
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "bob garbados" <bo**************************@yahoo.com> wrote in message news:10*************@corp.supernews.com...I am trying to create a database-driven photo gallery for a friend with
an admin form to upload images... I can upload a file to the web server,
but I want to store the image in a database and I want to resize the image before I save it... How do I take the uploaded .jpg and shrink it to a
thumbnail? How do I pass the uploaded .jpg to a stored procedure that will store
the image as an image datatype in SQL Server 2000? I'm developing this without Visual Studio.
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs) End Sub
Sub Button_Click(S as Object, E as EventArgs)
fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho togallery\NewFile.jpg") End Sub
</script> <html> <head> <title>Image Upload</title> </head> <body> <form id="frmUpload" method="post" runat="server" enctype="multipart/form-data"> <input type="file" id="fsoUploadFile" runat="server"><br/> <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/> </form> </body> </html>
I lied... removed the response.write and everything works beautifully.
"bob garbados" <bo**************************@yahoo.com> wrote in message
news:10*************@corp.supernews.com... Steve,
I can save the image in the database, but I can't retrieve it. Here's my code:
Dim con as SqlConnection Dim strConnectionString as String
strConnectionString = ConfigurationSettings.AppSettings("connection")
con= New SqlConnection(strConnectionString)
Dim dr As System.Data.SqlClient.SqlDataReader Dim cmdGetPhoto as new SqlCommand("usp_GetPhotos", con)
con.Open() dr = cmdGetPhoto.ExecuteReader If dr.Read Then Response.Write("Photo is here...") Response.Write("Photo Name: " & dr("PhotoTitle") & "<br/>") Response.ContentType = dr("PhotoThumbContentType").ToString Response.OutputStream.Write(CType(dr("PhotoThumb") , Byte()), 0, CInt(dr("PhotoThumbSize"))) Response.AddHeader("Content-Disposition", dr("PhotoTitle").ToString()) Else Response.Write("File Not Found.") End If
'close down the connection con.Close()
I stepped through the code and it executes the correct lines of code, but doesn't write anything and the image doesn't show up. What does the 'inherits="CIT.ViewAttachment"' line in your code do?
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message news:u6*************@TK2MSFTNGP11.phx.gbl... Here's an article I wrote that describes how to upload images into a database and get them back out again. http://steve.orr.net/content/asp200307so_f.asp
Also, here's an image resize routine I wrote:
/*shrink the image proportionately so that neither height nor width is more than [NewSize] pixels*/
public Image ShrinkImage(Bitmap bmp, int NewSize)
{
double NewWidth;
double NewHeight;
double ShrinkPercent;
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
if (bmp.Width>bmp.Height)
{
NewWidth=NewSize;
ShrinkPercent=(NewWidth/bmp.Width)*100;
NewHeight=(ShrinkPercent/100)*bmp.Height;
}
else
{
NewHeight=NewSize;
ShrinkPercent=(NewHeight/bmp.Height)*100;
NewWidth=(ShrinkPercent/100)*bmp.Width;
}
System.Drawing.Image myShrunkenImage =
bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero); return myShrunkenImage;
}
public bool ThumbnailCallback(){return false;}
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "bob garbados" <bo**************************@yahoo.com> wrote in message news:10*************@corp.supernews.com...I am trying to create a database-driven photo gallery for a friend with an admin form to upload images... I can upload a file to the web server, but I want to store the image in a database and I want to resize the image before I save it... How do I take the uploaded .jpg and shrink it to a thumbnail? How do I pass the uploaded .jpg to a stored procedure that will store the image as an image datatype in SQL Server 2000? I'm developing this without Visual Studio.
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs) End Sub
Sub Button_Click(S as Object, E as EventArgs)
fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho togallery\NewFile.jpg") End Sub
</script> <html> <head> <title>Image Upload</title> </head> <body> <form id="frmUpload" method="post" runat="server" enctype="multipart/form-data"> <input type="file" id="fsoUploadFile" runat="server"><br/> <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/> </form> </body> </html>
It's Friday and I've worked too long this week, but I can't figure this one
out... When I try to save the file to the database from my browser pointed
at localhost, it all works fine. When I try to do the same from a remote
machine, it doesn't work. It tries to upload the file from the server's C:\
drive instead of the client's C:\ drive. Any ideas? Is there a setting I'm
missing somewhere?d
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:u6*************@TK2MSFTNGP11.phx.gbl... Here's an article I wrote that describes how to upload images into a database and get them back out again. http://steve.orr.net/content/asp200307so_f.asp
Also, here's an image resize routine I wrote:
/*shrink the image proportionately so that neither height nor width is
more than [NewSize] pixels*/
public Image ShrinkImage(Bitmap bmp, int NewSize)
{
double NewWidth;
double NewHeight;
double ShrinkPercent;
System.Drawing.Image.GetThumbnailImageAbort myCallback =
new System.Drawing.Image.GetThumbnailImageAbort(Thumbn ailCallback);
if (bmp.Width>bmp.Height)
{
NewWidth=NewSize;
ShrinkPercent=(NewWidth/bmp.Width)*100;
NewHeight=(ShrinkPercent/100)*bmp.Height;
}
else
{
NewHeight=NewSize;
ShrinkPercent=(NewHeight/bmp.Height)*100;
NewWidth=(ShrinkPercent/100)*bmp.Width;
}
System.Drawing.Image myShrunkenImage =
bmp.GetThumbnailImage((int)NewWidth,(int)NewHeight ,myCallback,IntPtr.Zero); return myShrunkenImage;
}
public bool ThumbnailCallback(){return false;}
-- I hope this helps, Steve C. Orr, MCSD, MVP http://Steve.Orr.net "bob garbados" <bo**************************@yahoo.com> wrote in message news:10*************@corp.supernews.com...I am trying to create a database-driven photo gallery for a friend with
an admin form to upload images... I can upload a file to the web server,
but I want to store the image in a database and I want to resize the image before I save it... How do I take the uploaded .jpg and shrink it to a
thumbnail? How do I pass the uploaded .jpg to a stored procedure that will store
the image as an image datatype in SQL Server 2000? I'm developing this without Visual Studio.
<%@ Page Language="VB" %>
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs) End Sub
Sub Button_Click(S as Object, E as EventArgs)
fsoUploadFile.PostedFile.SaveAs("C:\FasterSolution s\Clients\spiritmt\www\pho togallery\NewFile.jpg") End Sub
</script> <html> <head> <title>Image Upload</title> </head> <body> <form id="frmUpload" method="post" runat="server" enctype="multipart/form-data"> <input type="file" id="fsoUploadFile" runat="server"><br/> <asp:button Text="Upload File" OnClick="Button_Click" runat="server"/> </form> </body> </html>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Daniel Kelly \(AKA Jack\) |
last post by:
Hi!
I'm searching for a Photo Gallery software package (like Coppermine and
Gallery) that works, from the ground up, like a database-driven app. In
other words, I want a gallery which entirely...
|
by: matt |
last post by:
I have this code, works perfectly on Windows server, but now i'm trying
to run it on a Linux server, the form submits, i get no errors, but the
photo doesnt upload, and the caption file doesnt...
|
by: Viken Karaguesian |
last post by:
Hello everyone,
Can anyone recommend a good online site to learn PHP? The W3Schools
website is quite lacking - leaves much to be desired. I'm sure there
are many places, but which ones are good?...
|
by: Throw |
last post by:
G'day everyone
I'm looking for a simple photo gallery script in PHP (or Perl), but not
too simple. I have tried several photo gallery scripts in either
language and I have found that they are...
|
by: Wayne Smith |
last post by:
I've come up against a major headache that I can't seem to find a solution
for but I'm sure there must be a workaround and I would really be grateful
of any help.
I'm currently building a web...
|
by: Mikee Freedom |
last post by:
Good Morning all,
New member to the list, hoping you might be able to give me some much
needed advice.
Basically, I have a client who would like to offer the ability for his
users to have...
|
by: Jumping Arne |
last post by:
I've searching for some software that would allow me to present my photos on
the web (I'm not interested a software that generates static pages that I
upload) and there are quite a few, see for...
|
by: Scott Sandeman-Allen |
last post by:
On 5/1/08, Jumping Arne (arnlen@mac.com) wrote:
I've been working with Photologue for a while with some nice results.
<http://code.google.com/p/django-photologue/>
It is a Django project ...
|
by: premprakashbhati |
last post by:
hi, good evening..
i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button()
here is the code ...its work fine...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |