Re: OK got it, BYTEA, PHP, Storing Images - Mailing list pgsql-general

From Joe Conway (wwc)
Subject Re: OK got it, BYTEA, PHP, Storing Images
Date
Msg-id 3C48924E.2040905@cox.net
Whole thread Raw
List pgsql-general
Thomas T. Thai wrote:

> if you look at the decode function, i had to put those 'search' strings in
> single quotes. i honestly don't know why it works with 5 backslashes
> there. maybe someone can figure this out.
>

> to encode for bytea:
>
> function encodeByteA($binData) {
>   // \000 = 00 = NULL,         \012 = 10 = VerticalTab,
>   // \047 = 39 = Single Quote, \134 = 92 = backslash
>
>   $search = array(chr(0), chr(10), chr(39), chr(92));
>   $replace = array("\\\\000", "\\\\012", "\\\\047", "\\\\134");
>   $binData = str_replace($search, $replace, $binData);
>   return $binData;
> }


Thanks!
BTW, later testing showed that escaping chr(10) was really unnecessary.

>
> to decode for bytea:
>
> function decodeByteA($binData) {

Why the decode function -- I thought stripcslashes() worked OK?

Joe


pgsql-general by date:

Previous
From: Andrew Sullivan
Date:
Subject: Re: large file limitation
Next
From: "Cornelia Boenigk"
Date:
Subject: Re: Need book on PHP and PostgreSQL