Forum Stats

  • 3,826,763 Users
  • 2,260,705 Discussions
  • 7,897,072 Comments

Discussions

Retrieving the image from Oracle database

1000034
1000034 Member Posts: 4
edited Apr 4, 2013 11:41AM in PHP
I am facing a issue in retrieving the image from the Oracle database and display it in IE8.0.

Images are partially loaded in IE8.0 but it is displaying correctly in Firefox.
After further research, I realized that IE has some issues with base64_encode and it displays only 32KB.

This is the snippet of code which I am using to get the image from the data. The size of the Image stored in the database is 270KB.

$img = $row['DOCUMT']->load();$b64Src = "data:image/jpeg;base64,".base64_encode($img);echo '<div><img src="'.$b64Src.'" alt="image" width="700" height="300" /></div>'

one more thing I noticed is after retrieving the Image from the database, image_type_to_mime_type($img) is returning as application/octet-stream.

Is it anything to do with this? I tried, $b64Src = "data:application/octet-stream;base64,".base64_encode($img);

Nothing is working.
Please don’t ask me why you cannot store the images in the server instead of database. I was told to find a solution to this issue.
Is there any way this issue can be resolved? I badly need your help and suggestion.

Answers

  • Christopher Jones-Oracle
    Christopher Jones-Oracle Member Posts: 1,648 Employee
    edited Apr 1, 2013 2:41PM
    Storing images in the DB is good.

    If you can't workaround the encoding issues with Windows PHP, or the IE8 issues with inline image display, what about creating a PHP file that displays only the image?
    Your original "<img src=" tag can refer to the URL of this file. This solution will have the overhead of an extra HTTP request to load the page, but
    with such a big image the extra request time may not be an issue. For an example, look at ac_logo_img.php on page 12-4 in http://docs.oracle.com/cd/E17781_01/appdev.112/e18555.pdf
    This can be used in an HTML page like: <img src="ac_logo_img.php">

    If you are intending to deploy your PHP application on a Linux machine, than I recommend also developing on Linux so you don't hit all these little file system issues that Windows is prone to.

    Edited by: cj on Apr 1, 2013 11:39 AM Corrected "<a src=" to be "<img src="
  • 1000034
    1000034 Member Posts: 4
    Thank You so much for the quick response. I will try this and will get back to you.
  • 1000034
    1000034 Member Posts: 4
    I tried to do the suggetion made by you but I was not able to solve the issue. I think I am close to it and with your help I should be able to resolve it. Let me explain you the brief about this issue.

    1. Another group uses Oracle Apex to load the images in to the database.
    2. I am fetching this data fron Oracle and displays in to Webpage using PHP.

    This is so far I tried. Please bear with me if I am doing anything wrong.

    1.I created program.php which calls the <IMG> as suggested by you.Snippet of the code is

    <div><img src="/oracle/image_story.php" alt="Image Stories" width="900" height="500" /></div>

    2. In the image_story.php, I used the following code.

    <?php

    $query = "SELECT *
    FROM IMAGE_STORY WHERE image_id = 50";
    if ($result = run_oracle($query, 'select')) { // Run the query.

    $num_results = count($result);
    if ($num_results > 0) {
    foreach($result as $row){
    $img = $row['DOCUMT']->load();
    header("Content-type: image/pjpeg");
    echo $img;
    //echo '<div><img src="'.$img.'" alt="Image Stories" width="900" height="500" /></div>';
    }
    }

    }
    ?>

    When I run the program.php,Image is not displayed and it is showing as "X". To troubleshoot the issue,I run the image_story.php and echo $img is giving me the weird character like,

    "ÿØÿàJFIFddÿìDuckyPÿîAdobedÀÿÛ„


    I used PL/SQL developer as a client to access the BLOB field from the database and in the HTML view, it is giving me the same output.

    Select * from image_story a where a.image_id = 50

    I am not sure the issue is with the MIME-TYPE,ENCODING or I am missing something here. I tried lot of Content-Type.

    Please guide me.
  • Christopher Jones-Oracle
    Christopher Jones-Oracle Member Posts: 1,648 Employee
    Verify the data is a valid image. Try writing it to a disk file with
    file_put_contents("/tmp/test.jpg", $img). Then from the operating
    system, load that file in an image editor.

    Check there is no white space before the <?php tag or after the ?> tag
    (many PHP programmers don't use the ?> tag to avoid this kind of
    issue). Temporarily use file_get_contents() to load the image from
    the file system instead of querying the DB.

    Check the Content-type code. Is "pjpeg" a typo in your code or in the
    forum post?

    Test using a different image.
  • 1000034
    1000034 Member Posts: 4
    This issues is resolved.

    The issue is that i was using an echo$query before the echo $img for the trouble shooting purposes and removed that while posting the snippet in this forum.

    Since you didn't find anything wrong with my code , i was looking at the submitted code in the forum and the actual one and was able to figure it out.

    Thanks a lot for your guidance in resolving this issue!
This discussion has been closed.