473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.binarywrite" 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_dbserver';
$sql_user = 'sql_user_name';
$sql_userpw = 'sql_user_password';
$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_userp w)) {
mssql_select_db($db,$conn);
$rs = mssql_query($query,$conn);
$arrImage = mssql_fetch_row($rs);
mssql_close($conn);
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.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
</head>
<body>
<table>
<tr>
<td>
Image: <img src="getimagefromdb.php?ID=1" />
</td>
</tr>
</table>
</body>
</html>

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

Sincerely,
Bjarte

Jul 17 '05 #1
4 2740
In article <rT*******************@news4.e.nsc.no>, Bjarte Andreassen wrote:

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.
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.
Here is my php code:

getimagefromdb.php
<?php
error_reporting(E_ERROR);
header("Content-type: image/jpg");


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().
Jul 17 '05 #2
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
Martin Wickman<wi*****@hotbrev.com> 18.09.2003 12:50:25 >>>
In article <rT*******************@news4.e.nsc.no>, Bjarte Andreassen wrote:
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.
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.
Here is my php code:

getimagefromdb.php
<?php
error_reporting(E_ERROR);
header("Content-type: image/jpg");


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().
Jul 17 '05 #3

In article <uJ*******************@news4.e.nsc.no>, bjartea @ hotmail.com wrote:

Please refrain from top posting. It sucks.
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...


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.
Jul 17 '05 #4
Yes, I included "datalength(coverImage) 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
Martin Wickman<wi*****@hotbrev.com> 18.09.2003 23:41:57 >>>

In article <uJ*******************@news4.e.nsc.no>, bjartea @ hotmail.com wrote:

Please refrain from top posting. It sucks.
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...


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.
Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob Manger | last post by:
Hi All, I am hoping someone can help me. I am trying to setup my main page so that when the user moves the mouse over an image, it changes the source (got this working). When the user CLICKS...
1
by: NMA | last post by:
I have a Visual Studio 6 project that was building correctly. I took a day off of that project to install .NET 03 for another project, then returned to my VS6 project the next day. Without any...
5
by: William Starr Moake | last post by:
I want to adapt the following alert script into an insert image dialog in my WYSIWYG editor, but I can't get it to write an image tag correctly. <head> <script> function getImageDims(imgurl)...
7
by: Andrew Poulos | last post by:
I'm using the following code to create a small table with one column and two rows. An image goes into the first cell. //create table var t = document.createElement("TABLE"); t.style.position =...
2
by: mike | last post by:
I've spent a couple of days on this and I'm to the "bang-my-head 'gainst the monitor and babble in tongues" mode. First - SuSE Pro 9.3, Linux 2.6.11.4-21.7, Apache 2.0.53, PHP 4.3.10 I have...
12
by: Joe Stanton | last post by:
Hello Group I have a query that works in Oracle and SQL Server, but fails in Microsoft Access. The query is: SELECT data fromTABLE1 WHERE data>='A&' AND data<'A''' Here is my sample data:
23
by: Peter | last post by:
I have a problem with a page show_image.asp that returns a jpg image under Windows XP Pro SP2. The page sets content type as: Response.ContentType = "image/jpg" While this works perfectly fine...
4
by: Mark S. | last post by:
Hello, On a high volume page we have the following JavaScript: img = new Image() img.src = 'http://myserver.com/count.aspx?x=1'; and it works fine, but now we've added: img.onload =...
4
by: Ben | last post by:
Hello, I'm trying to get an image from a webserver here in the network. I managed to create a socket connection and filter out the response headers. I load the body of the reply into a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.