From: | Ron Chmara <ron(at)opus1(dot)com> |
---|---|
To: | gidget(at)getitgear(dot)com |
Cc: | "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: OID output problems |
Date: | 2000-05-03 19:50:06 |
Message-ID: | 391082EE.7771B3@opus1.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
surfer girl wrote:
>
> The documentation on this is so scarse it's hard to figure out what the right format is supposed to be for all this. After much searching (websites, various mailing list archives), I found the "note" that PHP has a special variable "userfile" for file uploads.
It has a few.
/*
echo "<P>Original file name is <B>$userfile_name</B>\n";
echo "File size is <B>$userfile_size</B>\n";
echo "File type is <B>$userfile_type</B>\n";
echo "Temporary file name is <B>$userfile</B></font>\n";
*/
> This I have changed, and a straight upload to a file works OK, but the Postgres input does not. "$userfile" actually points to a file such as "/tmp/php12595baa" - now, my question is, how do I get the actual BINARY FILE into the database, and not the NAME of the TEMP FILE. (This, at least, explains the bizarre output).
>
> What I had put for my input was taken out of the Addison Wesley book but the explanation was not enough and frankly it's not working. I have yet to find another example of how to do this, and the function reference is cryptic at best.
>
> Any ideas would be absolutely appreciated. Thanks.
>
> --- "Ross J. Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
> > wrote:
> >> pg_Exec($conn, "BEGIN");
> >> $oid = pg_locreate($conn);
> >> $handle = pg_loopen($conn, $oid, "w");
> >> pg_lowrite($handle, $file);
> >
> >Hmm, based on my reading of the php4 docs, this will write the contents of the variable
> >'file' to the lo, expecting it to be a null terminated string. I'm not sure how you're
> >supposed to get binary data in there. Is 'file' by any chance, the name of your file,
> >not the contents?
PHP doesn't really have an "open this file into memory" function, but it _does_ allow
you to burst lines of a file in, with fgets/fputs, or to build an array out
of the file contents. So, you could run a loop (metacoded, not yet tested):
if($filetowrite = fopen ("$userfile", "rb") //rb is read binary, right?
{
while (!feof($userfile)) //as long as it's not end of file
{
$stringtowrite = fgets($userfile); //get a string
pg_lowrite($handle, $file); //write that string
/* Offhand, I have no idea how fgets will handle the chars in your */
/* file. It's supposed to read to a newline, so you might have to */
/* Put one back in, a "/n" in the string.... if your BLOB, however,*/
/* has no lines, well that's another problem. */
}
}
All this being said, a frequent recommendation from the PHP list is to store the
file, on your filesystem, in the filesystem database, outside of an additional
database layer (yes, filesystems are databases). Combining this recommendation
with the limits imposed by PostgreSQL on row size, it's fairly impractical to
be doubling up on the work to write into a postgres BLOB, rather than having
BLOB storage outside the DB itself, with DB pointing to it (via filename). Of
course, you loose the ability for the DB engine to search _within_ the BLOB...
HTH,
-Bop
--
Brought to you from boop!, the dual boot Linux/Win95 Compaq Presario 1625
laptop, currently running RedHat 6.1. Your bopping may vary.
From | Date | Subject | |
---|---|---|---|
Next Message | Cliff Rowley | 2000-05-03 20:20:48 | Re: [PHP3] Job openings (FreeBSD/C/php/postgresql) |
Previous Message | surfer girl | 2000-05-03 19:23:24 | Re: OID output problems |