Given a PHP bug tracker project with an SQL DB (MySQL, PostgreSQL, Oracle...), which should be able to store attached files for each bug.
How would you basically store info (file info and the file itself) on DB & disk?
e.g.
- DB: the table bug would have a related table bug_files having a bug_id field, and a filename field containing path to file on disk
- Disk: storing files in an efficient way (avoiding having too many files in a single directory), e.g. automatically create directories 1-1000, 1001-2000, etc. so we can have /1001-2000/1234/bugfile.jpg or random subdirectories like /z/e/x/q/1000_bugfile.jpg ?
...or are there a more efficient ways?
Thanks.
EDIT
It also depends on how you want to get to these files, do you use a back-end webpage that fetches all bugs and creates the links for you? Or do you get an e-mail after a bug occured and do 开发者_如何学Pythonyou have to find it manually? I don't think this choice mathers a lot.
Files would be listed / uploaded / downloaded through the bug tracking web application (=> HTTP upload / download).
Nobody except developers / sysadmins would be able to view the automatically generated directory structure (however it would be more convenient to have a "clear" structure).
I'd let the file system do its job (file storage). Databases can be used for file storage but it's not (generally) as efficient, e.g. the file data may be put in the database buffers - this in itself isn't bad, but it may take resources away from other tables, row data and reduce the performance of other queries.
Creating directories based on a meaningful combination of date and project names etc. would help reduce the performance loss when having many files in the same directory.
I'd strongly suggest using recognizeable directory structure, perhaps even date based or something that matches up with (parts) of your bug filename. F.e. '20110506-bugfile' would be in /2011/05/06/ Perhaps this is a little to matching and only 2011/05/ would be enough.
It also depends on how you want to get to these files, do you use a back-end webpage that fetches all bugs and creates the links for you? Or do you get an e-mail after a bug occured and do you have to find it manually? I don't think this choice mathers a lot..
A slightly different option is to add the file into your database in the table bug (http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx), then you don't have to create a directory structure, BUT, this would not allow you to find the files using an FTP ofcourse.
精彩评论