473,320 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 3016
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 directorystructure.
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_title" 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*******@crimaniak.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.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Aug 4 '05 #5
"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:el********************************@4ax.com...
On Thu, 04 Aug 2005 23:54:11 +0300, Alexey Kulentsov <cr*******@crimaniak.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.andyhsoftware.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 programmatically 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.com...
On Thu, 04 Aug 2005 23:54:11 +0300,
Alexey Kulentsov <cr*******@crimaniak.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
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...
9
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!!!...
61
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...
1
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...
2
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...
12
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...
3
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...
3
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...
5
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.