Re: Difference between storing files on folder and in mysql db



NC wrote:
On Jan 8, 8:56 am, missmoo <mor...@xxxxxxxxx> wrote:
I would like to know what the differences are in terms of security,
reliability and resources between storing user-uploaded images in a
file or storing them in a mySQL database.

The only significant difference is the DB server load. Since <img
data="*"> tags are not (yet?) commonly supported by browsers, you need
a separate instance of an image display script (and a separate
connection to the DB server) to display each image. So if your Web
page has 100 images on it, it will require 101 nearly simultaneous
connections to display itself and the images, as opposed to one
connection if images were stored in the file system. Granted, image
retrieval connections would be very short, but at high loads, this
architecture would be patently inferior to disk-based alternative.


Not true. <img> tags are handled identically by the client, whether the image comes from the database or the file system. The client doesn't know or care if the image is from a database or not.

Also, if you use MyISAM tables, storing large images in them will
bring you to the limit of table file size much more quickly. If your
average image is 1 MB and your file system's maximum file size is 2 GB
(there are still some older Linux servers whose file systems have this
constraint), you will only be able to store about 2,000 images until
your table exceeds the maximum allowed file size.


Few Linux implementations have a 2GB limit any more. Most are at least 4GB, and some implementations are much larger.

Also, the typical image size is *much smaller* than 1MB.

Additionally, you'll need to make sure that your MySQL server is
configured with a packet size large enough to transmit the entire
record, including the image. Up to MySQL 3.23, this limit was 16MB
for MyISAM tables. As of MySQL 4.0, situation changed; the effective
maximum length of LONGBLOB is determined by maximum packet size and
available memory.


MySQL easily handles this for you.

Our company is starting an image-competition soon, and I am not sure
if I should write the php script to insert the binary code into a
mySQL database or if I should just store the files in a dedicated
folder and the data about them in the mySQL database.

Large image sharing sites invariably stick to the second approach.
Moreover, images may be stored on separate servers, optimized for
serving static content.


An over-generalization. Many have images stored in the database itself.

I answered a similar question here a few months ago, take a look:

http://groups.google.com/group/comp.lang.php/msg/e44b33db1a37543b

Which system should I use? Is there a real difference between the two?

Only at high loads...

Cheers,
NC



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================

.



Relevant Pages

  • Re: large queries
    ... will make SQL queries on a mySQL database that results in very large ... There's a many:many relationship between correspondents and ... populate a JFrame and display it. ... I'm not claimimg this idea (store a minimal list and allow selecting from ...
    (comp.lang.java.databases)
  • Re: Why is this script so slow?
    ... | mysql database that has about 250 records in it. ... | When I use another script to extract the same data and display the ... | I can only conclude it is the script. ...
    (alt.php)
  • Re: Help in making links from mysql!
    ... > I have a mysql database with in the database i have ... > How can i display a link with only the title of the document stored?(easy ... You get the five last entries as you have done, ... You query first only the title and the id of the five last entries and ...
    (alt.php)
  • Simple From Generator accessing MySql
    ... I want a simple form generator in PHP that accesses a Mysql database. ... Options for display only, insert new record, and edit. ... I started writing my own, but I am out of time! ...
    (comp.lang.php)
  • Re: How to prevent connection string from being public?
    ... >I'm using a MySQL database from within some Perl cgi's. ... >make the connection, I have to supply the username/password ... I can't have my own webserver, ... it in either the script or in a config file. ...
    (comp.lang.perl.misc)