Discussions
Categories
- 196.9K All Categories
- 2.2K Data
- 239 Big Data Appliance
- 1.9K Data Science
- 450.3K Databases
- 221.7K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 550 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 545 SQLcl
- 4K SQL Developer Data Modeler
- 187K SQL & PL/SQL
- 21.3K SQL Developer
- 295.9K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.6K Development Tools
- 107 DevOps
- 3.1K QA/Testing
- 646K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 155 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 18 Java Essentials
- 160 Java 8 Questions
- 86K Java Programming
- 80 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 204 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 440 LiveLabs
- 38 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 171 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 232 Portuguese
Retrieving the image from Oracle database
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.
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
-
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=" -
Thank You so much for the quick response. I will try this and will get back to you.
-
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. -
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. -
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.