Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Dispaying Pic from Access Database
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Dispaying Pic from Access Database

 Post Reply Post Reply Page  12>
Author
groq View Drop Down
Newbie
Newbie
Avatar

Joined: 21 July 2003
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote groq Quote  Post ReplyReply Direct Link To This Post Topic: Dispaying Pic from Access Database
    Posted: 13 August 2003 at 2:57pm

Can anyone lead me to some code samples that will allow me to display pictures from an Access database using DNS-less ASP connection in a web browser? Any help or suggestions will be greatly appreciated!

Thank you,

GROQ

Back to Top
Magic View Drop Down
Newbie
Newbie
Avatar

Joined: 11 August 2003
Location: United Kingdom
Status: Offline
Points: 28
Post Options Post Options   Thanks (0) Thanks(0)   Quote Magic Quote  Post ReplyReply Direct Link To This Post Posted: 13 August 2003 at 3:45pm

Okay it's a long time since I did and Access Development work, but storying images in the database itself has always been a big no no. If for no other reason than the size constraints. (If you really want to do this look at SQL)

The best way, IMHO, is to set up a field that has the path / url to the image (Which can be in a common directory) and then use the path /url (in a var for easy coding) to load the image.

Only one note that I can think of, don't make the path too long (IE: 256 Char or less).

Mark



Edited by Magic
Back to Top
3BEPb View Drop Down
Groupie
Groupie


Joined: 07 August 2003
Location: United States
Status: Offline
Points: 81
Post Options Post Options   Thanks (0) Thanks(0)   Quote 3BEPb Quote  Post ReplyReply Direct Link To This Post Posted: 13 August 2003 at 3:57pm
Or, what I'm usually doing - define file naming logic, based on their database ID (like picture_221.jpg) and creating binary DB column. There's no significant difference in ASP coding to retrieve picture later with case, described by magic, but DB size become even less.
Back to Top
Bunce View Drop Down
Senior Member
Senior Member
Avatar

Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
Post Options Post Options   Thanks (0) Thanks(0)   Quote Bunce Quote  Post ReplyReply Direct Link To This Post Posted: 13 August 2003 at 4:34pm

Originally posted by 3BEPb 3BEPb wrote:

Or, what I'm usually doing - define file naming logic, based on their database ID (like picture_221.jpg) and creating binary DB column. There's no significant difference in ASP coding to retrieve picture later with case, described by magic, but DB size become even less.

DB size even less?? If you're storing your images in an Access database it will become enormous!  There are very few legitimate reasons for storing them there.

 



Edited by Bunce
There have been many, many posts made throughout the world...
This was one of them.
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 13 August 2003 at 6:58pm

I personally would not recommend that you store images in an Access database. I recently developed a web application with specials for a client. The client is able to upload pictures to the web site. The pictures are uploaded to a folder on the web server. You will have to ask your hosting company to create a folder that would allow you to upload pictures to. The name of the file is added to the database (ex: ImageName: logo.gif). Would you like to get some sample code?  

Back to Top
groq View Drop Down
Newbie
Newbie
Avatar

Joined: 21 July 2003
Location: United States
Status: Offline
Points: 14
Post Options Post Options   Thanks (0) Thanks(0)   Quote groq Quote  Post ReplyReply Direct Link To This Post Posted: 13 August 2003 at 9:11pm

Yes, I would love to get some sample codes.  I'm more interesting in displaying the pics in the browser.  Yes, any code will help.  Thank you.

GROQ

Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 13 August 2003 at 10:23pm

You will need to ask your web hosting company to create a folder on your server where you can upload files to it. You will also need to find out if your web hosting company supports ASP SmartUpload. I hope that this sample code will help.

Take a look at a form that you could create for this application:

<FORM NAME="frmPictures" ACTION="AddPictures.asp" METHOD="post"

onSubmit="return InputIsValid()" ENCTYPE="multipart/form-data">

<TABLE width=400 align=center valign="top" cellpadding=2 cellspacing=0 border=0 bgcolor=#cccccc>

<TR>

<TD align=right><STRONG><font face=arial size=-1>Name </font></STRONG></TD>

<TD><INPUT NAME="txtName" SIZE=30 > </TD>

</TR>

<TR> <TD align="right"><STRONG><font face=arial size=-1>Image</font></STRONG></TD>

'You will browse for an image file on your computer that you would like to upload to your web site:

<TD width="70%"><INPUT TYPE="file" name="file" size="35"></TD></TR>

<tr>

<td align=right>&nbsp;</td>

<td align=middle>

<INPUT

Type=submit

Name=subSubmit Value="Submit">&nbsp;<INPUT id=reset1 name=reset1 style="WIDTH: 74px; HEIGHT: 24px" type=reset value="Clear form">

</td></tr></TABLE></FORM>

 

Here's the sample code for the second page that will add and upload the picture. You will also add a name to the name field in the database.  

<%

' Variables

' *********

Dim mySmartUpload

Dim file

Dim Name

'Declare constants for a recordset that allows adding records

'You can also just include the file ADOVBS.INC to get these constants

Const adLockOptimistic = 3

Const adOpenDynamic = 2

dim connectionString, databaseName, path

dim sqlString

' Object creation

' ***************

Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")

' Upload

' ******

mySmartUpload.Upload

SpecialsName = mySmartUpload.Form("txtName")

 

' Connect to the DB

' *****************

' Open a recordset

' ****************

'Start sql string with Join

'Create the recordset

set rs = Server.CreateObject("ADODB.Recordset")

rs.Open sqlString, connectionString, adOpenDynamic, adLockOptimistic

' Select each file

' ****************

For each file In mySmartUpload.Files

' Only if the file exist

' **********************

If not file.IsMissing Then

' Add the current file in a DB field

' **********************************

fic="Upload/" &file.FileName&""

file.SaveAs(fic)

Rs.AddNew

Rs("ImageName") = file.FileName

Rs("Name") = Name

Rs.Update

End If

Next

 

' Destruction

' ***********

rs.Close

Set rs = Nothing

 

You said that you would like to know how to display the picture on a web page. I'll give you some code sample for the web page that will display the picture. You can figure out the code for everything else.

You should have something like this if you want to display a picture from a database:

<a href="Picture.asp?qryID=<%=rs("PictureID")%>"><img src=../Upload/<%= rs("ImageName") %> width="100" height="100" border="0" alt=<%= rs("Name")%>></a>

Back to Top
b_bonnett View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
Post Options Post Options   Thanks (0) Thanks(0)   Quote b_bonnett Quote  Post ReplyReply Direct Link To This Post Posted: 14 August 2003 at 4:20am

Note that you will have to remove the onSubmit="return InputIsValid()" code from the form, as you won't have the neccessary Javascript function on your site...

Blair

Webmaster, The Plane Gallery
Greetings From Christchurch
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.