Date: 05/29/01
- Next message: Klaus Seidenfaden: "Re: [phplib] pre-authorization page"
- Previous message: darcy w. christ: "[phplib] pre-authorization page"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi all,
I wrote a document management system using Perl some years ago. The
concepts still apply to PHP so I will try to summarize my thoughts on
this.
Should I store my files in the database?
In my opinion, NO! While it is possible to do this and it might be the
right thing to do in some cases (like text files that you want to search
on the contents) it is not generally a good idea for binary files and
images. Why:
1) the file system is more efficent
2) it is harder to serve them to the web and takes more CPU resources
eg: DB spools to PHP which spools to WebServer which spools to
Browser all processes active during transfer of file
vs. DB give info to PHP; PHP sends link to browser; web server spools
file to browser
3) you have to maintain the mime type in the DB as opposed to the file
extention
4) web servers are designed to efficently return files to browsers (see
2)
5) file backups are easily done with system utilities can be on separate
partition than DB
6) file versioning can easily be done my storing multiple file with
"version" as part of the file path, old versions can my moved offline
(see offline below)
Where do I put the files if I use files?
Upload to a temp directory and scan the file for virus, check the file
for other appropriate size, type, etc criteria.
Move the file to a respository directory tree and rename it based on its
unique id and mimetype extension. Then create the database record
referencing the file.
When a use searches or otherwise requests the file via the database,
create a link to the file based based on its unique id and when the user
clicks the link the webserver will return the file.
If you wanted to move some files offline because they are not requested
very often, then it would be simple to write a Perl/PHP script the scans
the DB looking for files that meet your criteria and update those
records as being offline, then removing those files to offline storage,
like a CD/DVD/Tape. When a user requests an offline file you can handle
it appropriately, like requesting their email address and queueing a job
to fetch the file from offline storage and emailing it to them. There
are obvious needs for manual intervention unless you have an automated
system.
It is best that you create the name for the file based on a unique id
then you avoid a host of other problems.
If you want to keep track of how many times files have been downloaded,
then create a link to a php script that updates the download count in
the DB and does a header("Location: http://..") to the file. This can
also be done to check for old versions and redirect to new versions.
I hope this helps, I am sure other people will have other opinions, but
this worked very well for me.
-Steve
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>
- Next message: Klaus Seidenfaden: "Re: [phplib] pre-authorization page"
- Previous message: darcy w. christ: "[phplib] pre-authorization page"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

