473,583 Members | 2,875 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting an image from a PHP source and ADOdb

Hi!

I am trying to display an image in my html document. The document contains
the following line:

<td class="Input">< img
src=getimage.ph p?tbl=dbo.Emplo yees&type=jpg&c ol=Photo&idCol= EmployeeID&id=1
Border=0 alt=''>&nbsp;</td>
This call getimage.php source. Following is the php source itself:

<?PHP
include_once('o rdersappdata.ph p');
$objConn1 = &ADONewConnecti on("mssql");
$objConn1->debug = $DebugMode;
$objConn1->Connect("serve r1","sa","sa200 0","northwind") ;
include_once('u tils.php');
$myQuote = "";
$objRSImage = "";
$strSQL = "";
$image = "";
$myType = "";

$handle = "";
$filename = 'test.txt';
$handle = fopen($filename , 'a');
//fwrite($handle, "Debug open");
//$myQuote = getQuote($objCo nn1, getGet("tbl"), getGet("idCol") );
$myQuote = "";
$strSQL = "select " . getGet("col") . " from " . getGet("tbl") . " where ";
$strSQL .= getGet("idCol") . " = " . $myQuote . getGet("id") . $myQuote;

//fwrite($handle, $strSQL . "\n");
$objRSImage = $objConn1->Execute($strSQ L);

if ($objRSImage):
//fwrite($handle, "Recordset OK" . "\n");
$image = $objRSImage->fields[getGet("col")];
$objRSImage->Close();
switch (getGet("type") ):
case "jpg":
//fwrite($handle, "Type = jpeg\n");
header("Content-type: image/jpeg");
$myType = "jpg";
break;
case "gif":
//fwrite($handle, "Type = gif\n");
header("Content-type: image/gif");
$myType = "gif";
break;
case "png":
//fwrite($handle, "Type = png\n");
header("Content-type: image/png");
$myType = "png";
break;
default:
//fwrite($handle, "Type = default\n");
if(ord($image[0]) == 255 && ord($image[1]) == 216 &&
ord($image[2]) == 255 && ord($image[3]) == 224):
header("Content-type: image/jpeg");
$myType = "jpg";
endif;
if(strcmp(subst r($image,0,3)," GIF") == 0):
header("Content-type: image/gif");
$myType = "gif";
endif;
if(ord($image[0]) == 137 && ord($image[1]) == 80 &&
ord($image[2]) == 78 && ord($image[3]) == 71 &&
ord($image[4]) == 13 && ord($image[5]) == 10 &&
ord($image[6]) == 26 && ord($image[7]) == 10):
header("Content-type: image/png");
$myType = "png";
endif;
endswitch;
header("Content-Disposition: attachment; filename=\"" . getGet("col") .
".$myType" . "\"\n");
header("Content-Transfer-Encoding: binary\n");
header("Content-length: " . strlen($image) . "\n");
//fwrite($handle, "filename=\ "" . getGet("col") . ".$myType" . "\"\n");
print($image);
unset($image);
endif;
unset($objRSIma ge);
$objConn1->Close();
unset($objConn1 );
fclose($handle) ;
?>
The image is not displayed in the html document. Is someone can tell me why
it is not?

Many thanks!

Pierre Tremblay
Jul 17 '05 #1
9 3333
Pierre Tremblay wrote:
The image is not displayed in the html document. Is someone can tell
me why it is not?


Loose the Content-Disposition and Content-Transfer-Encoding headers. The
Content-Length can also be left out in most cases.

BTW, when using GET or POST parameters to construct a query, it's always
advisable to validate them first, but I assume that the getGet() function
takes care of that?
JW

Jul 17 '05 #2
Hi!

Thanks for your reply!

I commented the corresponding header call as per your suggestion but
unfortunately, I still have no image in my html document.

The sql is ok (I even at some point used fwrite to write the content of the
recordset field in a file to verify that I retrieved something).

"Janwillem Borleffs" <jw@jwscripts.c om> wrote in message
news:41******** *************** @news.euronet.n l...
Pierre Tremblay wrote:
The image is not displayed in the html document. Is someone can tell
me why it is not?


Loose the Content-Disposition and Content-Transfer-Encoding headers. The
Content-Length can also be left out in most cases.

BTW, when using GET or POST parameters to construct a query, it's always
advisable to validate them first, but I assume that the getGet() function
takes care of that?
JW

Jul 17 '05 #3

[ TOFU corrected: <http://tk.digiserv.net/tofu.txt> ]

"Janwillem Borleffs" <jw@jwscripts.c om> wrote in message
news:41******* *************** *@news.euronet. nl...
BTW, when using GET or POST parameters to construct a query, it's always
advisable to validate them first, but I assume that the getGet() function
takes care of that?


On Thu, 9 Sep 2004 19:42:41 -0400, "Pierre Tremblay"
<pi*****@pierre tci.com> wrote:
Hi!

Thanks for your reply!

[ snip ]

The sql is ok (I even at some point used fwrite to write the content of the
recordset field in a file to verify that I retrieved something).

I think you're missing JW's point =)

It's not whether it retrieved anything, it's _validation_.

What happens when someone terminates the query early and appends
something like exec('rm -rf /'); to the query? Depending on the system
configuration, this could cause some headaches for some people =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #4
Hi!

Not sure if I follow you on this.

This is executed on my test machine (my workstation) and nothing is
terminating the query early. I know that field is a jpeg image and that
field is of type image (in the MSSQL design table screen).

Any help at this point will be greatly appreciated!

Many thanks!
The sql is ok (I even at some point used fwrite to write the content of therecordset field in a file to verify that I retrieved something).

I think you're missing JW's point =)

It's not whether it retrieved anything, it's _validation_.

What happens when someone terminates the query early and appends
something like exec('rm -rf /'); to the query? Depending on the system
configuration, this could cause some headaches for some people =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #5

[ TOFU corrected for the _last_ time, meet killfile next time ]

>The sql is ok (I even at some point used fwrite to write the content ofthe >recordset field in a file to verify that I retrieved something).

I think you're missing JW's point =)

It's not whether it retrieved anything, it's _validation_.

What happens when someone terminates the query early and appends
something like exec('rm -rf /'); to the query? Depending on the system
configuration, this could cause some headaches for some people =)


On Thu, 9 Sep 2004 21:08:48 -0400, "Pierre Tremblay"
<pi*****@pierre tci.com> wrote: Hi!

Not sure if I follow you on this.

This is executed on my test machine (my workstation) and nothing is
terminating the query early. I know that field is a jpeg image and that
field is of type image (in the MSSQL design table screen).

Any help at this point will be greatly appreciated!

Many thanks!

OK, I hadn't read your OP. I jumped on JW's bandwagon without realising
you're _reading_ from not writing _to_ the DB =)

From your OP code:
header("Content-Disposition: attachment; "filename=\ "" . getGet("col") . ".$myType" . "\"\n");
header("Content-Transfer-Encoding: binary\n");
header("Content-length: " . strlen($image) . "\n");

I see no Content-type header here. I don't use the above 3 headers for
displaying images, but you might find replacing those with:
header("Content-type: image/$myType");
will display your image (assuming the DB retrieval is all correct and
present).
HTH.

Regards,

Ian
PS: Please learn to post correctly, top-posting is _not_ the correct way
to reply to a post.

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #6
Ian.H wrote:
OK, I hadn't read your OP. I jumped on JW's bandwagon without
realising you're _reading_ from not writing _to_ the DB =)


When the user is permitted to both read and write, the following could
happen:

$sql = "select * from " . $_GET['table'];

script.php?tabl e=foo%3Bdelete+ from+foo

(this is a classic)
JW

Jul 17 '05 #7

"Ian.H" <ia*@WINDOZEdig iserv.net> wrote in message
news:6o******** *************** *********@4ax.c om...

OK, I hadn't read your OP. I jumped on JW's bandwagon without realising
you're _reading_ from not writing _to_ the DB =)

From your OP code:
header("Content-Disposition: attachment; "filename=\ "" . getGet("col") . ".$myType" . "\"\n"); header("Content-Transfer-Encoding: binary\n");
header("Content-length: " . strlen($image) . "\n");

I see no Content-type header here. I don't use the above 3 headers for
displaying images, but you might find replacing those with:


The Content-type is set in the switch statement in the code posted in the
original message.

here is the code snippet

switch (getGet("type") ):
case "jpg":
fwrite($handle, "Type = jpeg\n");
header("Content-type: image/jpeg"); <--------------- Here
$myType = "jpg";
break;
case "gif":
//fwrite($handle, "Type = gif\n");
header("Content-type: image/gif");
$myType = "gif";
break;
case "png":
//fwrite($handle, "Type = png\n");
header("Content-type: image/png");
$myType = "png";
break;
default:
//fwrite($handle, "Type = default\n");
if(ord($image[0]) == 255 && ord($image[1]) == 216 &&
ord($image[2]) == 255 && ord($image[3]) == 224):
header("Content-type: image/jpeg");
$myType = "jpg";
endif;
if(strcmp(subst r($image,0,3)," GIF") == 0):
header("Content-type: image/gif");
$myType = "gif";
endif;
if(ord($image[0]) == 137 && ord($image[1]) == 80 &&
ord($image[2]) == 78 && ord($image[3]) == 71 &&
ord($image[4]) == 13 && ord($image[5]) == 10 &&
ord($image[6]) == 26 && ord($image[7]) == 10):
header("Content-type: image/png");
$myType = "png";
endif;
endswitch;
header("Content-Disposition: attachment; filename=\"" . "Photo" .
".$myType" . "\"\n");
header("Content-Transfer-Encoding: binary\n");
header("Content-length: " . strlen($image) . "\n");
//fwrite($handle, "filename=\ "" . getGet("col") . ".$myType" . "\"\n");
print($image);:

Jul 17 '05 #8
On Fri, 10 Sep 2004 08:27:27 -0400, "Pierre Tremblay"
<pi*****@pierre tci.com> wrote:
From your OP code:
> header("Content-Disposition: attachment; "filename=\ "" .getGet("col" ) . ".$myType" . "\"\n"); > header("Content-Transfer-Encoding: binary\n");
> header("Content-length: " . strlen($image) . "\n");

I see no Content-type header here. I don't use the above 3 headers for
displaying images, but you might find replacing those with:


The Content-type is set in the switch statement in the code posted in the
original message.

here is the code snippet

switch (getGet("type") ):
case "jpg":
fwrite($handle, "Type = jpeg\n");
header("Content-type: image/jpeg"); <--------------- Here
$myType = "jpg";
break;

Ah crap, sorry about that, completely missed it =)

Appears a strange issue. Have you tried forcing a text/plain header to
see what the actual contents of your image are? or try writing the image
data out as an actual image and then trying to view it normally?

Just a couple of other things I might try if I had the same issue.

Regards,

tk

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/
Jul 17 '05 #9

"Ian.H" <ia*@WINDOZEdig iserv.net> wrote in message
news:c4******** *************** *********@4ax.c om...
On Fri, 10 Sep 2004 08:27:27 -0400, "Pierre Tremblay"
<pi*****@pierre tci.com> wrote:
Ah crap, sorry about that, completely missed it =)

Appears a strange issue. Have you tried forcing a text/plain header to
see what the actual contents of your image are? or try writing the image
data out as an actual image and then trying to view it normally?

Just a couple of other things I might try if I had the same issue.


I found the problem!

The fwrite statement gave me a clue when I added a line to write the len of
the data retrieved. No matter what row I was reading, all image field was
4096 bytes in length.

So a simple trip to php.ini and setting the text_limit and text_size entries
to a bigger size fixed the problem (default was 4096).

Many thanks again for your help!
Jul 17 '05 #10

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

Similar topics

3
22919
by: Vipul Pathak | last post by:
Hello Friends ! I have the Following Code, that Executes a Stored Procedure and Attempt to read a Returned Integer Value from the StoredProc. But It gives Error ... ADODB.Command (0x800A0BB9) Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. /C4U/DBOutputParameterTest.asp, line 25
0
7707
by: gm | last post by:
Immediately after generating the Access application from the Source Safe project I get: "-2147467259 Could not use ''; file already in use." If Access database closed and then reopened I get: "-2147467259 The database has been place in a state by user 'Admin' on machine ..... that prevents it from being opened or locked."
3
5813
by: CD | last post by:
An application is logging faxes sent in SQL2000 image column type. I have found code on the net but what it is doing is prompting to save to local which is fine for single page image. Not good for multiple page faxes. I have not been able to locate an example to load in the browser or how to handle multiple image in the one column. 1)...
24
6242
by: Manuel | last post by:
Is it possible to embed an image, like a company logo in a CDOSYS generated message? If yes, I´ll apreciate some code sample. I´ve been able to format messages in html the way I like, but I can't figure out how to embed an image. Thanks for your time. -- Manuel
2
2278
by: Chris3000 | last post by:
All i wanna do is simple, I wanna display an image from an access database. I try alot of things to no result. Like ascii code or nothing but a blank image with a red 'X'. Here is the code : <% set conn=server.CreateObject("ADODB.Connection") conn.Provider="Microsoft.jet.oledb.4.0" conn.Open(server.MapPath("test1.mdb"))
0
1636
by: bananularstyle | last post by:
Hi everyone, This is an issue I have been picking away at for the past two weeks and am running short of ideas. :-\ I am writing an ASP page that allows a user to open/save a tif image stored on SQL Server. The user triggers the download by clicking a hyperlink which loads getAttachment.asp (code listed below). GetAttachment.asp connects...
0
1075
by: Zw0n1m1r | last post by:
Hallo guyz! :-) I've some problems when I try to perform a image upload into a SQL Server 2000 DB Image field ... I've tried both with the ADO.NET method and the ADODB method: ------------------------ ADO.NET ------------------------ Dim cnn As New SqlConnection(strConnection) Dim workParam As New SqlParameter("@IPicture",...
0
3721
by: michels287 | last post by:
With a single record in my table, I can use this code: Private Sub Command1_Click() Set cn = New ADODB.Connection cn.Open "Provider=MSDASQL.1;Persist Security Info=False;" & _ "Data Source=localhost;Initial Catalog=testdb" Set rs = New ADODB.Recordset
3
3581
by: fran7 | last post by:
Hi, I have this nice code that returns a random image database record. It works great. What I am trying to do now is to be able to get the "alt" description for the image from another field. If I add another field to the query it returns two images. I was making the alt alt=""" & recordset(i) & """ but I know that must be wrong. well it works...
0
7888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7811
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8159
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8314
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8185
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.