Get image from DB fails. Image are not returned correctly.

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

    Get image from DB fails. Image are not returned correctly.

    Hi,

    I have a problem retreiving images from a MSSQL 2000 database with php. I wrote an ASP page using "response.binar ywrite" to get the same image, and this worked 100%. Therefore, the images in my database is not corrupt.
    Only the top part of the image is returned to the client's browser window. Same result with both IE6 and Opera 7.11.
    I guess the problem is header related, and I've tried to output different headers with no luck whatsoever.


    Here is my php code:

    getimagefromdb. php
    -----------------------
    <?php
    error_reporting (E_ERROR);
    header("Content-type: image/jpg");
    $sql_servername = 'name_of_dbserv er';
    $sql_user = 'sql_user_name' ;
    $sql_userpw = 'sql_user_passw ord';
    $db = 'database_name_ where_images_is ';

    $query = "SELECT coverImage FROM dvds WHERE id = ".$_GET['ID'];
    if (false != $conn = mssql_connect($ sql_servername, $sql_user,$sql_ userpw)) {
    mssql_select_db ($db,$conn);
    $rs = mssql_query($qu ery,$conn);
    $arrImage = mssql_fetch_row ($rs);
    mssql_close($co nn);
    echo $arrImage[0];
    }
    ?>


    Next is a simple example of a page requesting image with ID=1:

    index.php
    -----------
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
    </head>
    <body>
    <table>
    <tr>
    <td>
    Image: <img src="getimagefr omdb.php?ID=1" />
    </td>
    </tr>
    </table>
    </body>
    </html>





    I hope somebody can help me :-)
    Thans a lot in advance.

    Sincerely,
    Bjarte

  • Martin Wickman

    #2
    Re: Get image from DB fails. Image are not returned correctly.

    In article <rT4ab.30880$Hb .470365@news4.e .nsc.no>, Bjarte Andreassen wrote:[color=blue]
    >
    > Only the top part of the image is returned to the client's browser
    > window. Same result with both IE6 and Opera 7.11. I guess the
    > problem is header related, and I've tried to output different
    > headers with no luck whatsoever.[/color]

    Try getting the image using wget/lynx/curl just to make sure that it's
    not a browser problem. telnet is also an option for testing this.
    [color=blue]
    > Here is my php code:
    >
    > getimagefromdb. php
    ><?php
    > error_reporting (E_ERROR);
    > header("Content-type: image/jpg");[/color]

    Consider adding a Content-length header.

    Consider saving the image to file on the server and view the resulting
    file in a browser, thus verifying the image routines are not broken.

    Consider using flush().

    Comment

    • bjartea@hotmail.com

      #3
      Re: Get image from DB fails. Image are not returned correctly.

      Hi, and thanks for the clues...

      I've verified that the image is NOT transferred completely with lynx. Besides, I've tested retreiving the same images with an ASP script, and that works 100%.
      I've tested with flush() as well... No go...

      I'm therefore still looking for the right solution here... :-D

      Anyone???

      Bjarte
      [color=blue][color=green][color=darkred]
      >>> Martin Wickman<wizball @hotbrev.com> 18.09.2003 12:50:25 >>>[/color][/color][/color]
      In article <rT4ab.30880$Hb .470365@news4.e .nsc.no>, Bjarte Andreassen wrote:[color=blue]
      >
      > Only the top part of the image is returned to the client's browser
      > window. Same result with both IE6 and Opera 7.11. I guess the
      > problem is header related, and I've tried to output different
      > headers with no luck whatsoever.[/color]

      Try getting the image using wget/lynx/curl just to make sure that it's
      not a browser problem. telnet is also an option for testing this.
      [color=blue]
      > Here is my php code:
      >
      > getimagefromdb. php
      ><?php
      > error_reporting (E_ERROR);
      > header("Content-type: image/jpg");[/color]

      Consider adding a Content-length header.

      Consider saving the image to file on the server and view the resulting
      file in a browser, thus verifying the image routines are not broken.

      Consider using flush().


      Comment

      • Martin Wickman

        #4
        Re: Get image from DB fails. Image are not returned correctly.


        In article <uJgab.30965$Hb .472574@news4.e .nsc.no>, bjartea @ hotmail.com wrote:

        Please refrain from top posting. It sucks.
        [color=blue]
        > Hi, and thanks for the clues...
        >
        > I've verified that the image is NOT transferred completely with
        > lynx. Besides, I've tested retreiving the same images with an ASP
        > script, and that works 100%. I've tested with flush() as well... No
        > go...[/color]

        Did you try:

        Consider saving the image to file on the server and view the
        resulting file in a browser, thus verifying the image routines are
        not broken.

        Also, did you try:

        Consider adding a Content-length header.

        Comment

        • bjartea@hotmail.com

          #5
          Re: Get image from DB fails. Image are not returned correctly.

          Yes, I included "datalength(cov erImage) as Image" in my SQL query, and used the result in the Content-length header.
          Images are still not retreived correctly. Approx 10-20% of the image raster are displayed in the browser (different number of raster returned on different images).

          Next, I will try your last suggestion, and save the image to file. But I'm convinced that the images are okay, because they look absolute perfect when I retreive them with an asp script instead of php. Go figure... :-/

          I've tested this with php 4.3.2 and 4.3.3, by the way....
          I've also tested this on both IIS6 and Apache2.0.


          Anyways, thanks a lot...

          Regards,
          Bjarte


          [color=blue][color=green][color=darkred]
          >>> Martin Wickman<wizball @hotbrev.com> 18.09.2003 23:41:57 >>>[/color][/color][/color]

          In article <uJgab.30965$Hb .472574@news4.e .nsc.no>, bjartea @ hotmail.com wrote:

          Please refrain from top posting. It sucks.
          [color=blue]
          > Hi, and thanks for the clues...
          >
          > I've verified that the image is NOT transferred completely with
          > lynx. Besides, I've tested retreiving the same images with an ASP
          > script, and that works 100%. I've tested with flush() as well... No
          > go...[/color]

          Did you try:

          Consider saving the image to file on the server and view the
          resulting file in a browser, thus verifying the image routines are
          not broken.

          Also, did you try:

          Consider adding a Content-length header.


          Comment

          Working...