p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Dreamweaver (all versions) (http://p2p.wrox.com/forumdisplay.php?f=58)
-   -   Displaying photos via a database (http://p2p.wrox.com/showthread.php?t=40891)

Mike707 April 6th, 2006 09:03 AM

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


Imar April 6th, 2006 02:48 PM

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

Mike707 April 7th, 2006 06:03 AM

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


Imar April 7th, 2006 12:14 PM

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

Mike707 April 10th, 2006 09:01 AM

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


Imar April 10th, 2006 01:23 PM

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

Mike707 April 11th, 2006 07:50 AM

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


Imar April 11th, 2006 08:13 AM

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.

Mike707 April 13th, 2006 09:50 AM

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


Imar April 13th, 2006 10:43 AM

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.


All times are GMT -4. The time now is 12:05 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.