Jump to content


Photo

Storing files/attachments


  • Please log in to reply
7 replies to this topic

#1 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 29 September 2006 - 01:30 PM

This is something I have been thinking about.

Which would be the best option to store files (such as attachments)?

Option 1:
Have a database table called something like attachments where you store the mime-type, path of the file on the disk and other things about the file. The file is stored in a folder specified by a configuration file with a random filename generated like:
uniqid(md5(microtime()));

Option 2:
Same as for the database option 1, except that there will be one more field called data, which is where the contents of the file is stored in.

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 29 September 2006 - 03:15 PM

most definitely the first one. i used to actually use the second approach quite a bit, but its only a matter of time before things start grinding and problems crop up.
it also makes it easier to access your files directly should you need to, without extracting them from your database with a script first.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 29 September 2006 - 03:50 PM

Just increment a number, there's no need to go to any length to generate a random filename.

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 29 September 2006 - 05:13 PM

it also makes it easier to access your files directly should you need to, without extracting them from your database with a script first.


The point is that they would not be accessed directly.

#5 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 29 September 2006 - 05:23 PM

The point is that they would not be accessed directly.

ok cool. makes no difference to my answer though - definitely better to store a link rather than the file itself.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#6 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 29 September 2006 - 06:20 PM

You can store flatfiles without needing direct access. Just put them in a directory that is above the document root.

#7 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 29 September 2006 - 07:21 PM

You can store flatfiles without needing direct access. Just put them in a directory that is above the document root.


Just be aware that with this process, it is very easy to accidentally allow unregulated access to those files. If this route is taken, and you need to control who accesses the files and/or when they're accessed, or anything else, just make sure that you don't allow the clients to directly browse to those files.
http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#8 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 01 October 2006 - 09:03 AM

It would be something like this: download?id=16 then it could check it the user has permissions to download the file.

I'm not really going to make a script that does this, I just wondered what would be the best option. I would actually choose option 1, but I wondered if option 2 was better since databases are designed to handle data.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users