Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: PHP and Images

  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Posts
    216
    Thanks
    9
    Thanked 0 Times in 0 Posts

    PHP and Images

    Hello,

    I am having problems finding a site to instruct me on how to retrieve images from a MySQL database, I wonder if anyone could help me. This is the sql of the table used to store the images.

    Code:
    CREATE TABLE `images` (
      `PremTeamID` mediumint(15) NOT NULL,
      `ImageID` mediumint(15) NOT NULL auto_increment,
      `ImageName` varchar(15) collate latin1_general_ci NOT NULL,
      `Image` blob NOT NULL,
      PRIMARY KEY  (`ImageID`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=4 ;
    I am totally lost on how to retrieve the images. Any example scripts would be really useful. thanks.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Here's a link that contains a pretty good explanation why storing images in blob type fields is a bad idea:

    mysql forum post

    But if you still want to, the way to do it is via imagecreatefromstring().

  • #3
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    That explanation isn't very good, misses out options that involve DB storage, but not a PHP-based rendering. An example:

    page is loading,
    code looks up which images are associated with the page,
    checks to see if the images exist in the disk-cache,
    if they don't it pulls them and puts them there,
    the src in the img tags refers to this known cache location.
    Avoids all the flaws that article mentions, and has the benefit that you can have the CMS system (where you upload the images) separate from the website, with a shared database.

    We have a single CMS system for all our clients that is on a machine of it's own. The database is on a machine of its own. We have a separate 'farm' of load-balanced web-servers handling the sites.
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


  •  

    Posting Permissions

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