tags:

views:

43

answers:

2

HI

This is in reference with my earlier question http://stackoverflow.com/questions/2361723/how-to-organize-files-created-dynamically-using-php

I edited the question , with one more aspect, that is storing paths in to the DB.are there any advantages or disadvantages of doing this ?

A: 

How else are you going to find the file?

No Refunds No Returns
Just 'cause you haven't explicitly stored the path, doesn't mean you can't generate the path from what you have stored.
Frank Farmer
@NoRefunds: More of a comment, no?
Jonathan Sampson
+5  A: 

If you have no other way of finding the file, storing its path in the DB is probably OK.

Still, a couple of notes :

  • I would generally try to see if I could "guess" the file's path from another field -- for instance, from the primary key
    • If it's possible, then, there is no need to store the path in the DB, as it would be some redundant information
  • I would, as much as possible, store some relative path, and not an absolute one.
    • For instance, I would store images/my/image-test.png
    • But not /var/www/images/my/image-test.png
    • That way, moving the directory with the images to another place, or changing of server, using a new one with another path to the DocumentRoot, would still be OK and not break my application.
Pascal MARTIN
True; if you can find the path using the ID it's useless to store it in the DB. What I do for example, is only store the file extension (for my image hosting section) and fetch `uploads/{$img->id}.{$img->ext}`.
henasraf
I generally do kind of the same ;; I also often store the size *(in bytes)* and the content-type of the file : those two informations can be useful, when it comes to sending the file.
Pascal MARTIN