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
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
Comment