Grow your CSS skills. Land your dream job.

Blob display is truncated

  • # September 22, 2009 at 1:41 pm

    I’m new to php and have spent a good deal of time trying to figure out how to (correctly) display a SQL IMAGE field. I’ve finally gotten an image to render but it’s only partially displaying the image (the rest of the image is grey – like it ran out of ink). The images are either 4098 bytes or 8194 bytes (which seems to me to indicate that something is suppressing file size or it’s really coincidental).

    I’m accessing a third party database and they’ve not included an image’s file size in the database. The images that’ve been stored are all different sizes ranging from about 250px to about 700 px.

    The smaller images render correctly about halfway then turn to grey. The larger images are correct for only about 10 px/lines and then turn to grey.

    Here’s what a larger/8194 bytes image looks like: [img]http://dl.getdropbox.com/u/17533/displayCAD7KQM8.jpg[/img]

    Here’s the code that I’m using:

    PHP Code:
    display.php

    Code:
    < ?php
    $id = $_GET['id'];
    $linkweb = mssql_connect($ip, $un, $pw)or die(mssql_get_last_message());
    mssql_select_db ($db, $linkweb);
    $sql = "SELECT Photo, ClientID
    FROM tblClient_Photo
    WHERE ClientID=$id";
    $result = mssql_query($sql,$linkweb) or die('Query failed: '.$sql);
    if(mssql_num_rows($result)){
    while($row = mssql_fetch_array($result)){
    header("Content-type: image/jpeg;");
    $photo=($row['Photo']);
    print $photo;
    }
    }
    ?>

    The display line is as follows: <img src=’display.php?id=".$id."’>

    Let me know if there’s any other information you need to consider this problem.

    I will add this – I did post this on the Codewalkers forum and got some response. Also, the images are being accessed via an application and are rendered correctly in Word (which to my mind says the images aren’t corrupt?!). The oddly regular size of the image files would indicate to me that either a php.ini, SQL setting (or ?) is at work but because I’m rather inexperienced with both I’m really at a loss.

    I appreciate any insight or help provided.

    # September 22, 2009 at 4:24 pm

    A blob can only contain a certain amount of bytes. Maybe they could set it to a longblob and see if the whole photo gets uploaded.
    Or better yet, use the file system for storing photos and only put the link to the photo in the database.

    # September 22, 2009 at 5:25 pm

    (FYI: This is a SQL database so it’s using the IMAGE field.)

    I understand what you’re saying and that makes sense but if the images were too large wouldn’t there be an issue with their display in the application? How does that work?

    At this point I’d LOVE to dispense with images being stored as blobs (or at the very least store them with accompaning size and type info) but it’s not my database…

    Thanks for the input!

    # September 29, 2009 at 7:26 am

    This could be an issue with the MS SQL driver. I would start by examining the textsize and textlimit variables in php.ini – apologies if you have already done this.

    Code:
    mssql.textlimit = 65536
    mssql.textsize = 65536
    # September 29, 2009 at 9:43 am

    I found reference to this elsewhere and changed the settings as follows:

    Code:
    ; Valid range 0 – 2147483647. Default = 4096.
    ;mssql.textlimit = 2147483647

    ; Valid range 0 – 2147483647. Default = 4096.
    ;mssql.textsize = 2147483647

    Unfortunately it didn’t seem to make a difference.

    I think this is the right track though – it’s some sort of restriction in php or SQL. I thought maybe it’s a timeout issue but the images load fairly quickly – faster than the timeout threshold. Seems like if it was due to SQL setting that there would also be problems with the application display – I think…

    # September 29, 2009 at 11:31 am

    Those settings start with ; which indicates a comment. This means the default setting applies, which would explain why you are only able to get the first 4096 bytes of the file.

    Remove the ; from mssql.textlimit and mssql.textsize and restart apache. That should put the new settings into effect.

    # September 29, 2009 at 11:40 am

    Hmmm, have I mentioned that I’m new to PHP?

    As far as I know it’s running on iis not apache – unless that’s not possible, in which case it’s running on both. I know apache requires a restart – is that true for iis as well?

    Thank you.

    # September 29, 2009 at 11:49 am

    I couldn’t say for certain about IIS but I would say probably yes it would need a restart in order to load the new settings.

    Cheers
    Dave

    # September 29, 2009 at 2:23 pm

    Turns out you do have to restart iis (and take out the comment demarcation) and wonder of wonders it’s all working!

    So thank you, Dave!

    I owe you an ale, eh?

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".