473,396 Members | 2,023 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,396 software developers and data experts.

Images, bytea and pg_escape_bytea, pg_unescape_bytea

Hello,

I hope someone can help me with this problem - I'm getting nowhere
fast and have been working on it for a week.

All I'm trying to do is upload an image, store the image in a bytea
column of a postrgresql database, pull the image out of the datbase,
and verify that the image is still the same and it can be viewed by a
browser - that's all. The upload part works fine... I'm having
problems getting out what I put in. The file sizes (original image,
output image) never match and the browser is never happy.

Here's the basic setup:
PHP Version 4.3.2,
PostgreSQL 7.4.1 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.2.3
20030502 (Red Hat Linux 3.2.3-24)

I've tried about every possible combination of:

0. Upload the image no problem, browser can see it, and it works.

1. read from gif or jpeg file into string called $image

2. $bytea_image = pg_escape_bytea($image);

3. save $bytea_image in bytea column of postresql database

4. read $bytea_image back out from bytea column

5. $image = pg_unescape_bytea($bytea_image);

6. write $image back to disk

7. view image with browser - doesn't work.
pg_unescape_byte() doesn't seem to work at all - the string is always
truncated, maybe at a byte that's equal to NULL?
I've also tried:

5. $image = stripcslashes($bytea_image);
Better, but the output file is not the same size as the input file!!!
And, the output file does not render in a browser.
I've also tried at the Postgresql side doing the following:

5. SELECT encode(image_column::bytea, 'escape') FROM mytable LIMIT 1;

Still not correct...
So, here are my questions:
1. Does pg_unescape_bytea() actually work in PHP?
2. Is there a character set setting in Apache, Postgresql, or PHP that
has to be set for the escape and unescape to match?
3. Has anyone else had this problem?
I've found another way around this for now - I'm encoding the image as
hex, saving it, reading it back and converting it back to decimal and
it works no problem - but I'm obviously not using bytea as intended
and the image is now using two times the storage space to store an
image...

Thanks for any help,

Brian
Jul 17 '05 #1
0 2842

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

Similar topics

3
by: bissatch | last post by:
Hi, I am wanting to learn how to store images in a postgreSQL database. I have got as far as uploading the file using a file/browse field on an html form and have been able to catch the file...
2
by: bissatch | last post by:
Hi, I am trying to write script that is run when a form is submitted. The form contains an image input field and when submitted, the image is uploaded, resized and added as binary information to...
2
by: Alvar Freude | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I want to change a column from text to bytea; since it seems that alter table can't change the column type, i have to add a temporary column...
0
by: Alvar Freude | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, the following I posted already on pgsql-bugs -- perhaps someone has a good workaround or fix or can say me that I'm wrong? There seems to...
4
by: David Garamond | last post by:
May I request that connectby() supports BYTEA keys too? My keys are GUID (16-byte stored in BYTEA). In this case, branch_delim does not make sense because the keys should be fixed-length anyway,...
7
by: C G | last post by:
Dear All, What's the best way to store jpgs in postgresql to use in a web page? I tried to use large objects, but how would you extract them from a table to be viewed in a web-page without...
16
by: Michal Hlavac | last post by:
Hello, I am working on web portal. There are some ads. We have about 200 000 ads. Every ad have own directory called ID, where is 5 subdirectories with various sizes of 5 images. Filesystem...
7
by: Dennis Gearon | last post by:
when bytea, text, and varchar(no limit entered) columns are used, do they ALWAYS use an extra table/file? Or do they only do it after a certain size of input? Also, if I wanted to put a *.pdf...
4
by: Jerry LeVan | last post by:
Hi, I am adding image and large object support in my Cocoa postgresql browser. Are there going to be any enhanced bytea support functions coming along? It seems sorta silly to have to write...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.