Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Dreamweaver (all versions) section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 6th, 2006, 09:03 AM
Authorized User
 
Join Date: Apr 2006
Location: Perth, , Australia.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Displaying photos via a database

I want to display photos on a DW MX 2004 page but I don't want to store the picture in the Access 2003 database - instead, I want to use a pointer in the database to point to a file were the picture is located. How do I do that? What type of database field do I use and what does the pointer consist of, ie, what 'value' does it have?

Thanks in advance for any help,

Mike
Perth, Australia

  #2 (permalink)  
Old April 6th, 2006, 02:48 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Mike,

While I am sure other people may have different opinions on this, I'd like to store the images as a virtual root path. That way, you can easily move your site to a different location, and things will still work.

E.g. I store something like

/Images/Uploads/2006/04/SomeFile.gif

Using Server.MapPath you can easily translate this to a physical path. When the time comes you have to move your image to a folder outside your web root, you can add a virtual folder to your site, call it Images and things will still work.

My 2 cents....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
  #3 (permalink)  
Old April 7th, 2006, 06:03 AM
Authorized User
 
Join Date: Apr 2006
Location: Perth, , Australia.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Thanks for your reply. The reason I'm keen on using a database is so that I can store info about the images, such as a brief description, dimensions of the object shown, materials used etc, which would be held in different fields and then displayed in a DW table along with the image. That means I need to associate the images with info held in the database and hence why I'd like to use a pointer in the db to link to the image in the image file.

Any thoughts?

Regards,

Mike

  #4 (permalink)  
Old April 7th, 2006, 12:14 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think you misunderstood me. The path I provided:

/Images/Uploads/2006/04/SomeFile.gif


*is* the pointer to the image in the database. So, you can have a table like this:

Images
==========
Id
ImageUrl
DateUploaded
ContentType
Extension

In the ImageUrl file, you'd store the virtual path to the image on disk.

Does that answer your question? If not, there is some confusion....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
  #5 (permalink)  
Old April 10th, 2006, 09:01 AM
Authorized User
 
Join Date: Apr 2006
Location: Perth, , Australia.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

I'm having some trouble getting this to work. What data type should the ImageUrl you described be? Also, when I use Server.MapPath, do I just put that in the DW Connection file with the DSN definition?

Regards,

Mike

  #6 (permalink)  
Old April 10th, 2006, 01:23 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Mike,

You may be getting confused by a few concepts...

The ImageUrl can be simple text, with a length of 255 or so, depending on where you store the image.

When you upload a file, you'll do something like this (pseudo code)

File.Save(Server.MapPath("UserUploads") & "/" & FileName)

assuming that filename holds something like SomeFile.gif.

Next, you save the image URL in the database. All you store in the ImageUrl field is "/UserUploads/SomeFile.gif"

If you need to display the image somewhere on a page, you can use this:

<img src="<%= myRecordset("ImageUrl") %>" alt="" />

This puts an image location like this in the page:

<img src="/UserUploads/SomeFile.gif" alt="" />

which should be the virtual location of your file.

If you ever need to delete the file, you can do something like this (pseudo code again)

File.Delete (Server.MapPath(myRecordset("ImageUrl"))

Server.MapPath returns the physical location of the file, so the instruction translates to:

File.Delete (C:\UserUploads\SomeFile.gif")

Note: to actually process the uploaded files and save them to disk, you need some component that is capable of that. SA File Up, or ASP Upload are two good controls for uploading files.

Also, the connection string has nothing to do with this. You connect to your database like you always do (assuming you know how to do that) and all you pass is the ImageUrl and some other data about the image.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
  #7 (permalink)  
Old April 11th, 2006, 07:50 AM
Authorized User
 
Join Date: Apr 2006
Location: Perth, , Australia.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

Thanks very much for your response - it looks like just what I need. Unfortunately, I've had a bit too much West Australian wine tonight to be able to work on this, so I'll get back to you tomorrow!!

Prost! (Ich weiss das Wort auf Deutsch aber es tut mir leid, ich weiss das nederlandische Wort nicht!)

Mike

  #8 (permalink)  
Old April 11th, 2006, 08:13 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hahaha. The Dutch word is very similar to the German one: Proost instead of Prost.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
  #9 (permalink)  
Old April 13th, 2006, 09:50 AM
Authorized User
 
Join Date: Apr 2006
Location: Perth, , Australia.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Imar,

I'm still having a problem: I've added an image holder onto my page and then set the source to be <%=(Recordset1.Fields.Item("Image").Value)%> I did this by dragging the Image field from the Bindings tab. Now, when I view the page in the browser, the image holder appears with one of those little X things, ie I can't see the image. When I right click the image holder (in the browser), the Properties shows http://localhost/CFusionMX/wwwroot/Barlows/Images/1.jpg which is the correct path to the image. What am I doing wrong?

By the way, I haven't used the Server.MapPath on my page anywhere because I'm not writing to the database, just trying to use the pointer in the ImageURL field (as you used) to get the image from a file. Also, just to check, in my database, the pointer is using a Text datatype field and is not enclosed with either ' or " characters.

See ya,

Mike

  #10 (permalink)  
Old April 13th, 2006, 10:43 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Are you sure this is the right path:

http://localhost/CFusionMX/wwwroot/Barlows/Images/1.jpg

The CFusionMX/wwwroot folder sounds like the physical root of the site within the webserver, so maybe the path should be:

http://localhost/Barlows/Images/1.jpg

or even

http://localhost/Images/1.jpg

How do normal URLs to images look like?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.




Similar Threads
Thread Thread Starter Forum Replies Last Post
Serializing photos/files to a database w/ MySQL ironchef Pro JSP 1 December 19th, 2007 11:28 PM
How to add 5 more photos js32821 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 September 3rd, 2007 12:48 PM
Ridiculus photos shapira BOOK: Professional Crystal Reports for VS.NET 0 March 7th, 2005 08:11 PM
Uploading Photos microchip Classic ASP Basics 6 April 25th, 2004 10:15 AM
Photos in access kev_79 Access 1 July 24th, 2003 02:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.