BLOB Field

Discussion in 'PHP' started by Arsench, Jan 7, 2008.

  1. #1
    Hello world,

    Can you please help me.I have a blob field and want to insert and read image, but don't know how to do that.I want to insert data with images into mysql db and then read that in php.


    Thank a lot
     
    Arsench, Jan 7, 2008 IP
  2. mvl

    mvl Peon

    Messages:
    147
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are hardly any good reasons to store image in a database although it is technically possible. It is probably a better idea to store them in the filesystem and keep reference records in the database, containing filenames etc. If you allow people to upload those images make sure you store them outside of the webtree for security reasons. Use a wrapper to display them to the browser:

    
        ...
        // First tell the browser we are going to send an image, in this case asumme it is a .PNG image
       Header('Content-type: image/png');
       // send it to output, assume $imagefile contains the full path to our image
       readfile($imagefile); 
    ...
    
    Code (markup):
    If the image is stored in a database you will need to store it in a way that you can use imagecreatefromstring() to recreate the image from it. Read the comments on this php.net page, there is an example on how to read it from a db.
     
    mvl, Jan 7, 2008 IP
  3. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150