Specifications

Databases Versus File Storage
An important decision to make at an early stage is how the content will be stored after it has
been uploaded into the system.
Because we will be storing metadata alongside the story text, we have chosen to put the text
parts of the content into the database. Although MySQL is capable of storing multimedia data,
we choose to store uploaded images on the file system. As discussed in Part II, Using
MySQL, using BLOB data in your MySQL database can reduce performance.
We will just store the image filename in the database. Using the file system, the <IMG SRC> tag
can reference the image file directly as usual.
When a large amount of data is being stored, it is important to optimize your data store. Just as
the database would require proper indexes to be efficient, the file system will benefit greatly
from a well thought out directory structure.
An example of this can be seen in Figure 26.1.
Building Practical PHP and MySQL Projects
P
ART V
590
a/ ajs23.jpg
b/
c/ cp331.jpg, clo95.jpg
d/ dd332.jpg
x/ xz113.jpg
y/ yw632.jpg, yo224.jpg, yz775.jpg
z/
pictures/
FIGURE 26.1
This directory structure has been structured for file uploads.
The file system in this case is split into directories representing the first character of each file-
name. 10,000 files would therefore be spread across 26 directories with around 400 files in
each directory. This would be much quicker to access than 10,000 files all in one directory. It
is worth pointing out that the filename used should be generated by the upload processing
script to ensure that it is unique.
The example in Figure 26.1 assumes that all filenames will start with a lowercase letter.
32 7842 ch26 3/6/01 3:36 PM Page 590