 |
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
|
|
|

April 6th, 2006, 09:03 AM
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 6th, 2006, 02:48 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

April 7th, 2006, 06:03 AM
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 7th, 2006, 12:14 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

April 10th, 2006, 09:01 AM
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 10th, 2006, 01:23 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

April 11th, 2006, 07:50 AM
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

April 11th, 2006, 08:13 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|

April 13th, 2006, 09:50 AM
|
Authorized User
|
|
Join Date: Apr 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |