473,226 Members | 1,387 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,226 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 2820

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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.