SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: images in MySQL

  1. #1
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    images in MySQL

    back with anotha....

    Am trying to build a sort of online photo album and was wondering if when users upload a picture, does it physically get stored in the DB or does the DB just contain the URL to the file on the server? ps. I don't LIKE to sound dumb, just curios like George. Cheers!

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't sound dumb at all. When you upload a file you need to decide what to do with it. As you posted, you can either store the file in the database or details of the file. I would recommended never storing images or other files in the database, as it is very inefficient. Just uploaded the file, move it to a directory using move_uploaded_file() and store the details in your database

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thankya seanf! exactly what i'm looking for, much appreciated.

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your welcome

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to add further -

    some people like to name uploaded files the same as the client had them named - if you do that there is a chance of overwriting older files named the same (ie two people upload me.jpg and the older gets overwritten)

    personally I find it best to use an auto_increment field in the database and name the file according to that - eg 1.jpg 2.jpg 3.jpg etc - you could pull the extension through using getimagesize()
    teckis - that's news to me.

  6. #6
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, i don't mean to be rude (i'm a newbie!!) but this problem could be alleviated if every user was associated a unique Id, in which a directory would be named after and all images they upload be stored in there?

  7. #7
    SitePoint Evangelist
    Join Date
    Nov 2001
    Location
    UK
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup - unless of course they uploaded two files from different folders on their PC that were named the same
    teckis - that's news to me.

  8. #8
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    coo, i'm gettin it now... cheers pootergeist

  9. #9
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could even go like this:

    User uploads file: Get's unique ID, name file "1.jpg"
    Store ID in Database, with the original filename as a column
    When serving the file, you can use
    PHP Code:
    header('Content-Disposition: inline; filename="' $row['original_filename'] . '"'); 
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  10. #10
    SitePoint Zealot poLka's Avatar
    Join Date
    Apr 2003
    Location
    GF
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i love how different everyone thinks, nice suggestion.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •