SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Location
    St Catharines, Ontario, Canada
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    display an image (.PNG) stored as a blob in Mysql

    Here is an example of the code I've tried - as recommended from several searches...
    code working in directory:
    http://localhost:8000/cc/fleetadmin/

    //get blob (logo)
    $sql = "SELECT logo FROM files WHERE fleetnumber='$fleetnumber'";
    $query_results = mysql_query($link, $sql);
    header("Content-type: image/png");
    echo '<img src="'.mysql_result($query_results, 0).'">';

    I stored a .png in the variable logo in table 'files'
    I get the message "the image "http:///localhost:8000/cc/fleetadmin/" cannot be displayed because it contains errors

    <<< that's a PHP message - does it contain a clue to what I'm missing??? I've tried with mysqli_query & mysqli_result - same thing

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Umm...yeah you do not use HTML when outputting binary data like an image. The HTML has to go into a different page that calls for the image. Now unless you actually need to have the images stored within MySQL, it would be better to have them stored on the file system accessible via the web server and only store the path in the database.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)
    if you absolutely must store it in the database, then point your image tag to another PHP file, which contains something to the effect of:

    header('Content-Type: image/png');
    echo $imagedata;

    But as logic_earth pointed out, it's recommended to store the image data seperately and just put a link to the file in the database.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


Tags for this Thread

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
  •