SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Export picture from mysql database to file

    Hi all,

    I'm new to export picture from mysql database to file.

    I found few tutorials over the internet. All the tutorials show that in order to export the image file, I need to know the file extension.

    However, the file type of the images are not kept separately in one field in the database.

    Do you have any idea to get the image file exported with the correct file type from the database?


    Thanks in advance!
    newbie...

  2. #2
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are using blob field for storing image in mysql then you can just base64 decode and use the force download script.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Quote Originally Posted by PHPycho View Post
    If you are using blob field for storing image in mysql then you can just base64 decode and use the force download script.
    Thanks for your suggestion PHPycho...
    I'll try to explore on it..

    One more thing i wish to find out...

    Will there be any problem if I ignore the original file type of the image and export them in jpg format?
    newbie...

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by liyenn View Post
    Will there be any problem if I ignore the original file type of the image and export them in jpg format?
    There will be, for some users, yes. If whatever program they use to view the image tries to rely on the extension, and the contents of the file are not in fact a jpeg-encoded image, then they won't be able to see it.

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    There will be, for some users, yes. If whatever program they use to view the image tries to rely on the extension, and the contents of the file are not in fact a jpeg-encoded image, then they won't be able to see it.

    Hmm.. Thanks Dan Grossman...


    A silly question here:

    If I manage to view the file after downloaded from server, then everything should be fine right?
    newbie...

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It's fine for you, but not for all image viewers. If you want it to be fine for everyone, then the file extension should match what's in the file.

    I bet you can figure out the real file type looking at just the beginning of the file, then send the right extension and content-type headers. Just look up the specification for the image formats you've stored and figure out what the file contents look like.

    Write a little program that examines each BLOB, figures out what file type is in there, and updates a new column to store the type. Then you won't have this problem when it's time to send that file to someone.

  7. #7
    SitePoint Zealot
    Join Date
    Nov 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    It's fine for you, but not for all image viewers. If you want it to be fine for everyone, then the file extension should match what's in the file.

    I bet you can figure out the real file type looking at just the beginning of the file, then send the right extension and content-type headers. Just look up the specification for the image formats you've stored and figure out what the file contents look like.

    Write a little program that examines each BLOB, figures out what file type is in there, and updates a new column to store the type. Then you won't have this problem when it's time to send that file to someone.

    Thanks again Dan Grossman..

    I'll listen to your advice
    newbie...


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
  •