storing images

Discussion in 'Programming' started by jnm, Jun 23, 2007.

  1. #1
    not sure if this would be the right forum, but what is the best way to store images for profiles of a social networking type site?

    image server? folder for each user?

    i'm looking for speed.

    thanks.
     
    jnm, Jun 23, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    Image server would increase speed.

    * Rename uploaded file to a random #
    * Insert that random name into the database & associate it with the user.

    Peace,
     
    Barti1987, Jun 23, 2007 IP
  3. MartiCode

    MartiCode Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It really depends. For very small images (thumbnails, smileys, etc.) a database is usually more convenient because all your datas are stored together in one place, and backups are easy.

    Databases however usually don't like storing large binary datas, so for big pictures you might want to store them on a server and keep track of them in the database (if you have a table dedicated to pictures, you can use the primary key to name each file for example)
     
    MartiCode, Jun 24, 2007 IP
  4. InFloW

    InFloW Peon

    Messages:
    1,488
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The best system I think is putting them into directory called say images. Then from there just giving them the name of the primary key + random #. So maybe you do 292-3939393 with the longer number being the date.

    Of course for keeping things sane you may want to do a structure like say:

    images/userid/key-date.jpg
     
    InFloW, Jun 24, 2007 IP
  5. ProgrammersTalk

    ProgrammersTalk Peon

    Messages:
    684
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    how many images that one user can store for their profile? :-/
     
    ProgrammersTalk, Jun 25, 2007 IP
  6. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #6
    mmm, BLOB's baby! Gotta love having everything contained in a database. For speed, this isn't the prime solution but their are many advantages to using db-contianed blob data.

    Like:
    - Ability to protect your binary files (not accessible anywhere).
    - Ability to backup, modify, create new data and not worry about file/folder permissions
    - many more....
     
    ccoonen, Jun 25, 2007 IP
  7. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Do not store your images in database it will dramatically decrease your server speed. More over there is no point in keeping binary data in database, what will you do with it besides taking huge amounts of data from your database just to display an image.

    Keep them in folders, how to organize them?

    It is up to you, you can create folder for every user, keep all images in one folder named like userId-img543.jpg etc.
     
    Greg Carnegie, Jun 25, 2007 IP
  8. MartiCode

    MartiCode Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    That's an issue easely fixed: use a script and/or mod_rewrite to cache the image on the Web server so that it is only retrieved from the database once in a while.
     
    MartiCode, Jun 26, 2007 IP
  9. zonzon

    zonzon Peon

    Messages:
    100
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    hum, I vote to this solution:
    - ease of portability and backup
    - speedup


    but there's a drawback, storing images in blobs fields will enlarge your databases backups and restores.... maybe using a different DB for images? :rolleyes:

    the solution for this kind of problem is like the chicken or the egg problem!
     
    zonzon, Jun 26, 2007 IP
  10. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Well but it doesn't change a fact that image is already in your database so whenever you want take something out of this database, images you are storing in DB are "slowing down" your database.

    This is a partial fix then.
     
    Greg Carnegie, Jun 27, 2007 IP
  11. MartiCode

    MartiCode Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    That really depends. Take for example MySQL with the default MyISAM tables: each table has its own file. So stuffing lots of pictures in one table has no impact on the other tables, and as such no impact on their speed.
     
    MartiCode, Jun 28, 2007 IP