1

Possible Duplicate:
Thousands of images, how should I organize the directory structure? (linux)

i'm building a custom e-commerce, and one of it's functionalityes is to store user files on the web.

I read that storing files on DataBase sucks, and the right is to put only the path to the file.

But, what's the best way of storing those files? I mean, i can't just upload the file, and save them as they are...

  • I tought in something like this:
  • I will start with a folder called 0001, and before copying the file to the folder, i will check: "is the folder with the maximum size i want?", if yes, then it will create a new folder (0002) {and i don't know how is the best way, to before uploading, knowing what's the biggest folder}.
  • After uploading, the name that i will set, will be based on 2 things:
    • The hashed id of the user (with a random security) with a underline _
    • Plus, a random hash of the size with a underline _
    • Plus a random hash, based on a random number
    • Plus the same file extension (IS THIS RIGHT? if, the user upload a .php file, will it !@#! my server?)

Is it good enough? Or did i forgot something?

I have never worked with lots of file uploads, that require to be restricted ("not sequencial"), and i would apreciate any tips!

Thanks

Community
  • 1
  • 1
Ivan Seidel
  • 2,394
  • 5
  • 32
  • 49
  • http://stackoverflow.com/questions/900512/thousands-of-images-how-should-i-organize-the-directory-structure-linux – hackattack Aug 03 '12 at 00:21
  • 1
    "i can't just upload the file, and save them as they are" why not ? –  Aug 03 '12 at 00:22
  • @Dragon Because if the user, or another user, upload a file with the same name, then there would be a conflict... – Ivan Seidel Aug 03 '12 at 00:24
  • 90% of what you suggest has nothing to do with that issue, so i still don't understand the problem you are trying to fix. –  Aug 03 '12 at 00:26
  • @Dragon As i said, I'm trying to build the file structure... there is no problem to fix, because i haven't coded anything, i'm just thinking on the file structure, BEFORE coding... and if something is not right, i would loose time doing some useless code. – Ivan Seidel Aug 03 '12 at 00:30
  • @hackattack, Thanks! That's a simpler idea, but i think that fits =] – Ivan Seidel Aug 03 '12 at 00:31
  • 1
    @IvanSeidel instead of md5'ing the filename, I would prefix the users id or something since you're dealing with multiple users that may upload the same filename – Aaron W. Aug 03 '12 at 00:33
  • @AaronW. was going to do that, but wasn't shure that was something 'good'. Do i need to put the hashed user id, or it's useless? And should i use the MD5 Checksum of the file to put after the id? – Ivan Seidel Aug 03 '12 at 00:36

0 Answers0