php blob - display in html table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • adam

    php blob - display in html table

    Hi, I have an issue that i just cant seem to figure out hope some one
    can help.

    right i am getting people to input the own images directly into a blob
    within a mysql database. then on the next page i want to display the
    image with in a nicely formatted html table so i can put the image
    where i choose on the page

    *this code is only putting the image on the top of the page and wont
    let me output any other text etc*

    here is the code to display the blog image file-
    <?php

    $id;

    // you may have to modify login information for your database
    server:
    @MYSQL_CONNECT( "localhost","ro ot","admin");

    @mysql_select_d b("tablename" );

    $query = "select bin_data from binary_data where id=$id";
    $result = @MYSQL_QUERY($q uery);

    $data = @MYSQL_RESULT($ result,"bin_dat a");

    echo $data;


    ?>
    <html>
    <head>
    <title>Untitled </title>
    </head>

    <body>

    </body>
    </html>


    Please i am most grateful to any one that can help best regards adam
  • Bent Stigsen

    #2
    Re: php blob - display in html table

    adam wrote:[color=blue]
    > Hi, I have an issue that i just cant seem to figure out hope some one
    > can help.
    >
    > right i am getting people to input the own images directly into a blob
    > within a mysql database. then on the next page i want to display the
    > image with in a nicely formatted html table so i can put the image
    > where i choose on the page
    >
    > *this code is only putting the image on the top of the page and wont
    > let me output any other text etc*[/color]

    This is more or less pure luck. Some browsers defaults to showing plain
    text when the content of the response is undefined.

    There was a thread a while ago, on how to mix html and binary imagedata.
    But I would not recommend it for ordinary web-use.

    Stick to having a specific content-type for each webrequest.

    [color=blue]
    > here is the code to display the blog image file-
    > <?php
    >
    > $id;[/color]

    Dont require register_global s
    $id = $_GET['id']
    [color=blue]
    >
    > // you may have to modify login information for your database
    > server:
    > @MYSQL_CONNECT( "localhost","ro ot","admin");
    >
    > @mysql_select_d b("tablename" );[/color]

    ? dbname
    [color=blue]
    > $query = "select bin_data from binary_data where id=$id";
    > $result = @MYSQL_QUERY($q uery);
    >
    > $data = @MYSQL_RESULT($ result,"bin_dat a");[/color]

    //you may want to store the image type with the imagedata
    Header("Content-Type: image/jpeg");
    [color=blue]
    > echo $data;[/color]

    //end request
    exit;
    [color=blue]
    >
    > ?>[/color]
    [snip]

    /Bent

    Comment

    • adam

      #3
      Re: php blob - display in html table

      thanks so far...

      but what is the code i need to use to be able to display both html and
      the blob in an html table this is wot i need urgently i have been
      trying for hours with out success. thanks people

      Comment

      • Michael Fesser

        #4
        Re: php blob - display in html table

        .oO(adam)
        [color=blue]
        >thanks so far...
        >
        >but what is the code i need to use to be able to display both html and
        >the blob in an html table this is wot i need urgently i have been
        >trying for hours with out success. thanks people[/color]

        Usually you need two scripts: One for delivering the HTML, another for
        the binary stuff, because the browser has to request two resources from
        the server. The HTML then contains an img-element with a link to the
        second script, which delivers the image with the correct content-type
        header:

        <img src="yourImageS cript.php" alt="...">

        It's also possible to embed binary data in a HTML document with using
        the data scheme, but that's not supported by all browsers, e.g.

        <img src="data:image/jpeg;base64,bas e64-encoded data follows" alt="...">

        RFC 2397 - The "data" URL scheme


        Micha

        Comment

        Working...