views:

143

answers:

2

I am attempting to add a document storage module to our AR software.

I will be prompting the user to attach a doc/image to thier account. I will then put a copy of this file into our folder so that we can reference it without having to rely on them keeping the file in its original place. This system is not using a database but instead its using multiple flat files.

I am looking for guidance on how to handle these files once they have attached them to our system.

How should I store these attached files?

I was thinking I could copy the file over to a sub directory then renaming it to a auto-generated number so that we do not have duplicates. The bad thing about this, is the contents of the folder can get rather large.

Anyone have a better way? Should I create directories and store them...?

+1  A: 

This system is not using a database but instead its using multiple flat files.

This sounds like a multi-user system. How are you handing concurrent access issues? Your answer to that will greatly influence anything we tell you here.


Since you aren't doing anything special with your other files to handle concurrent access, what I would do is add a new folder under your main data folder specifically for document storage, and write your user files there. Additionally, you need to worry about name collisions. To handle that, I'd name each file there with by appending the date and username to the original file name and taking the md5 or sha1 hash of that string. Then add a file to your other data files to map the hash values to original file names for users.

Joel Coehoorn
It's pretty hard to explain without writing a book. We are in essence using two systems at once. The files use index file that are give read/write access to other users. We don't have any real issues with files being in use since the most that are using it at one time around 10 users. That help any?
ErocM
I'd say you've been very lucky so far not to have corruption and missing data issues. 10 users is more than enough to cause problems: say on a friday afternoon right at month end when everyone is trying to get things resolved all at once.
Joel Coehoorn
There is more to it, but honestly, I don't see what that has to do with my problem. I'm only asking what is a good option to saving the documents I import into my system without loosing track of them and still be able to utilize them in the best way.
ErocM
A: 

Given your constraints (and assuming a limited number of total users) I'd also be inclined to go with a "documents" folder -- plus a subfolder for each user. Each file name should include the date to prevent collisions. Over time, you'll have to deal with getting rid of old or outdated files either administratively or with a UI for users. Consider setting a maximum number of files or maximum byte count for each user. You'll also want to handle the files of departed users.