Loading image from database with inconsistent results across servers
I am loading images from a single PostgreSQL database shared currently by my production and development instances. This is already a little inaccurate - the production server isn't live yet, which is why it's okay they share a DB. The software itself is written in PHP5.3.
The issue is this: my ima开发者_如何学JAVAge storage routine works on both servers. An image stored using either branch can be displayed properly in the production branch. However, the images are completely nonviewable on the production side.
Invoking the image display script directly yields the discovery that the data returned by each is markedly different. The production server provides (excerpt):
‰PNG IHDR99zÒ IDAThL&³Ùaaaýýýþþþþþþþþþýýýýýý" ø÷øëðïêññçîîàëêßêêìööPPP;'(8&'"þþúúüýýýþþÿþõÛëìÇÙÙÈÞÝòúúLLL P45B-,üý÷÷ýýÿÿÿÿþþþÿýýþþÿÿþþÿ íÿºÒÒµÕÔòúúKKKÿÿÿF**]=?ýýõõÿÿÿ
while the development server delivers (excerpt):
x89504e470d0a1a0a0000000d4948445200000039000000390802000000037a14d200002000494441546805014c26b3d9016161610000000000000000000000000000000000000000000000000000000000000000000000000000000
for the same image. Curiously, the development server's response echoes what the actual database appears to be storing.
The relevant code appears to be identical between instances. Investigating php.ini yields only minor differences relating to error reporting. I'm all but certain this is a server communication issue but I am at a loss as to what exactly is causing it.
You got a configuration mismatch :
http://www.postgresql.org/docs/9.0/static/runtime-config-client.html#GUC-BYTEA-OUTPUT
I guess that the returned data are the same, but in one case the string is displayed as raw output, in the other case is given in output as an hex string.
As you can see here 89 50 4E 47 0D 0A 1A 0A
is the magic number for png files and if you convert it in ascii you'll obtain \211 P N G \r \n \032 \n
which are the content of the first 8 byte of the first output.
So you have to find why in one case the output is hex and in the other is raw, maybe a postgres settings or it could depend on how you're retrieving and displaying the content using php.
You should try to output the content of the image field using the command line or a tool which is not related to php. If in this way the output is the same you can restrict the search to your php.ini settings (in this case you should post some code on image retrieval).
Conversely if the output differs at postgres level you should investigate on your postgres settings on both servers.
精彩评论