473,748 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing images instead of image paths in DB

Hi,

I am currently writing a news admin system. I would like to add the
ability to add images to each article.

What I have always done in the past is uploaded (using a form) the
image to a folder on the server and then in the database table that I
INSERT the news article, I'll store the path of the uploaded image.

To me this seems a bad idea as if the image paths were changed on the
server (cant think why, but still worth considering) the database
wouldnt reflect this.

The other alternative would be to store the images in the database.
This way the images and the image path wouldn't be two seperate
entities. Is this is preferred option? If so, where can I learn more?
Also, the databases I am using is PostgreSQL (this cant change). Does
this support storing data entries?

Any suggestions would be much appreciated, thanks

Burnsy

Aug 4 '05 #1
6 3046
I think you should store images in database only if your site ofted
moves, cos storing images in database greatly load your database, which
may result in lose of speed.

Ofcource PostgreSQL suports storing images in database, it's just your
script work to convert it to useble form

Read more on
http://codewalkers.com/tutorials/35/3.html

Aug 4 '05 #2
bi******@yahoo. co.uk wrote:
Hi,

I am currently writing a news admin system. I would like to add the
ability to add images to each article.

What I have always done in the past is uploaded (using a form) the
image to a folder on the server and then in the database table that I
INSERT the news article, I'll store the path of the uploaded image.

To me this seems a bad idea as if the image paths were changed on the
server (cant think why, but still worth considering) the database
wouldnt reflect this.

The other alternative would be to store the images in the database.
This way the images and the image path wouldn't be two seperate
entities. Is this is preferred option? If so, where can I learn more?
Also, the databases I am using is PostgreSQL (this cant change). Does
this support storing data entries?
Well, why should you WANT to change from PostgreSQL?
It is a great robust database, and free.
Keep using it. :-)

And I never understood why people like to store images in databases, when
you can much more easily store them in a directorystruct ure.
Images only make your databasefiles much larger, and offer no extra
functionality.
(Unless you think that 'storing images in database' is the extra
functionality.)

you can easily achieve the same functionality by only storing the name (and
maybe path) of the image in the database.

So my advise: Don't. Just store the path to the image in the database.

One possible problem you might encounter is the fact that if more people can
upload images, you overwrite files with the same name.
So do not let the client choose the name of the image, be sure you pick it.
eg:
<articleid>_img .png
or
<articleid>_img .jpg

Just my 2 cents.

Regards,
Erwin Moller

Any suggestions would be much appreciated, thanks

Burnsy


Aug 4 '05 #3
bi******@yahoo. co.uk wrote:

To me this seems a bad idea as if the image paths were changed on the
server (cant think why, but still worth considering) the database
wouldnt reflect this. No problem. Use abstract image tag in articles and translate it to
real tag before output. User must know only image ID to insert it to
article. For example <preview id="123"/> or <image number="123"/>
After translation result will be like <IMG
SRC="path/to/images/pic_123.jpg" ALT="$image_tit le" WIDTH="xxx"
HEIGHT="yyy" AND_SO_ON.. />
If you will change your paths structure you just correct translation
procedure and all links in articles will be valid.
The other alternative would be to store the images in the database.

Never store image in database. Database can't index images so you have
no any reason to store it in SQL server.
Aug 4 '05 #4
On Thu, 04 Aug 2005 23:54:11 +0300, Alexey Kulentsov <cr*******@crim aniak.com>
wrote:
The other alternative would be to store the images in the database.

Never store image in database. Database can't index images so you have
no any reason to store it in SQL server.


Untrue - two clear advantages are:

(1) The image data is under the same transactional control as the rest of the
data. If your server crashes, then you don't have any guarantee that the
filesystem is in sync with the database any more. And you can't ROLLBACK a
filesystem change.

(2) Having the images in the database means you only have to backup one thing,
and similar to (1) you know that your image data is referentially correct
compared with the rest of the data.

There are disadvantages to storing image data in the database, some of which
can be alleviated with caching in the filesystem, but to say there is no reason
to store images in the database is not true.

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Aug 4 '05 #5
"Andy Hassall" <an**@andyh.co. uk> wrote in message
news:el******** *************** *********@4ax.c om...
On Thu, 04 Aug 2005 23:54:11 +0300, Alexey Kulentsov <cr*******@crim aniak.com> wrote:
The other alternative would be to store the images in the database.Never store image in database. Database can't index images so you have
no any reason to store it in SQL server.


Untrue - two clear advantages are:

(1) The image data is under the same transactional control as the rest of

the data. If your server crashes, then you don't have any guarantee that the
filesystem is in sync with the database any more. And you can't ROLLBACK a
filesystem change.

(2) Having the images in the database means you only have to backup one thing, and similar to (1) you know that your image data is referentially correct
compared with the rest of the data.

There are disadvantages to storing image data in the database, some of which can be alleviated with caching in the filesystem, but to say there is no reason to store images in the database is not true.

--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool


I have to agree with Andy on this one... for both reasons he pointed out.
And most of the time you can pull in your image data right along with
everything else in the same query. If you have a small number of images you
would be ok to do it either way and the filesystem method would probably not
be too bothersome but, if you are looking to be storing thousands or more
then you will probably need to programmaticall y break up the directory
strucure so as to not overload the filesystem (too many files in one
directory can really slow down a filesystem, not to mention the filesystem
limitations) such as alphabetically, numerically, etc. The GD functions
really make this easy by the way.

Norm
---
FREE Avatar hosting at www.easyavatar.com
Aug 5 '05 #6
NC
Norman Peelman wrote:
"Andy Hassall" <an**@andyh.co. uk> wrote in message
news:el******** *************** *********@4ax.c om...
On Thu, 04 Aug 2005 23:54:11 +0300,
Alexey Kulentsov <cr*******@crim aniak.com> wrote:
Never store image in database. Database can't index images so you have
no any reason to store it in SQL server.


Untrue - two clear advantages are:

(1) The image data is under the same transactional control as
the rest of the data. .... (2) Having the images in the database means you only have to
backup one thing,


I have to agree with Andy on this one... for both reasons he pointed out.
And most of the time you can pull in your image data right along with
everything else in the same query.


As a matter of fact, most of the time you can't do it. You need
a separate script to pose as a picture. So if you have a page
that pulls text data and references three images, you will have
four nearly simultaneous connections, one for the text page and
three for three instances of picture-rendering script.

This could quickly change at some point if all browsers begin to
understand the <img data=""> tag; then there will be no need for
separation of HTML and image output. Unfortunately, we are not
quite there yet...

There is also a workaround, whereby the HTML-rendering script
retrieves image data from the database and stores images in
session variables and then passes the variable names to
picture-rendering scripts, which retrieve image data not from
the database, but from the session variable referenced.

Andy is absolutely right when he says that storing images in a
database leads to stricter transactional control and easier data
maintenance. But the developer needs to understand that this
architecture creates additional overhead that cannot be overcome
from within PHP; Andy's proposed solution is to cache images,
which is another way of saying "store image copies on disk, but
keep normative versions in the database".

Actually, a similar approach is used by some content management
systems which allow for separation of authoring and publishing.
An author submits text and images; they are stored in a database.
When the editor publishes the submission, static HTML and image
files are created (not necessarily on the same physical machine).

Cheers,
NC

Aug 5 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2507
by: Bernie Raffe | last post by:
When I change the 'cookieless' flag in the WebConfig file to true, everything works fine on my local PC, but the images fail to appear when using the remote server. I specify my images throughout using a relative directory structure, such as 'images/topbanner.jpg'. I tried changing this to ~/images/topbanner.jpg and .../images/topbanner.jpg, but this didn't work locally so I didn't even bother trying it out remotely. Tthe problem...
9
2373
by: Adam J Knight | last post by:
Hi all, Just wondering whats everyones prefered method of storing images ? 1) File System 2) Database (SqlServer) (Seems to be easier, but has a performance hit) Appreciate some insight!!! Cheers,
61
4741
by: phil-news-nospam | last post by:
Why does SVG need a different tag than other images? IMHO, SVG should be implemented as an image type just like any other image type, allowing it to work with <img> tags, and ... here is the important part ... also work with backgrounds in other tags. I fail to see any wisdom in making SVG different than say PNG (of course the implementation of the rendering code would obvious be different). --
1
3232
by: Xah Lee | last post by:
The following is a program to generate thumbnail images for a website. Useful, if you want to do that. It is used to generate the thumbnails for my “Banners, Damsels, and Mores” project gallery. ( http://xahlee.org/Periodic_dosage_dir/lanci/lanci.html ) Comments and versions in other lang welcome. Xah
2
2284
by: Frankie | last post by:
Using SQL Server 2005 and .NET 2.0; I'm creating a Windows Forms application that will need to display photos of people, along with a bunch of information about each person. In a Web application, there is a generally accepted "best practice" of storing only a string (the path to the .jpg file name), with the actual file stored in an NTFS folder (and not in the database). What's the standard practice for Windows Forms applications? Is...
12
3866
by: John Kotuby | last post by:
Hi all, Maybe this is a simple problem found in ASP.NET 2.0 course 101, but I must have missed it. When I create a page in Visual Web Developer and use URLs like "/images/picture.gif " or a link like <a href="../../Search/page.aspx">, everything works fine as long as I publish the site to a root web like http://localhost. However, I am developing on my local C drive in c:\development\project. I
3
2299
by: ABCL | last post by:
Hi I have asp.net web site that is working well on my m/c if I access using http:// But I depyoed on production,It requiers to use https:// , If i browse tha page using https://...and on login page it doesn't link images, css and .js files on the login page. Once the user login successfully and try to browse login page agian, The images and .js files are working fine what can be problem? how to solve it?
3
1839
by: John Kotuby | last post by:
I have just upgraded to a new development machine that came with Vista ultimate. I am developing a website with VS2005 and VB. My image and css references in my source code are all relative. For example http://root.com/images/some.gif in my source is just /images/some.gif. When I publish to the root web on any IIS server, that works just fine. On my old XP machine I had registered a custom version of multisite.dll with a config.ini like...
5
13378
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
8983
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9359
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9236
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6792
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6072
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4592
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3298
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.