From: Mitch Vincent <mitch@venux.net>
To: justinlong@strategicnetwork.org
To: Pgsql-Php <pgsql-php@postgresql.org>
Subject: Re: Question re large objects
Date: Tue, 28 Nov 2000 11:16:54 -0800
Message-ID: <00f901c0596f$c5903c60$0200000a@windows> (raw)
References: <PBEMJIMKFNACLPCNPDEBMEMOEHAA.justinlong@strategicnetwork.org>
Sure, you could break the image up into pieces -- you just need to be sure
you put every byte right back where you got it in the whole image.. All in
all I think storing images for display on web pages in any database is much
more trouble than it's worth...
A flat file system with a naming scheme should work rather well (I use
something like this in several applications to deal with MS-Word documents
and the like).. You could even store the image as a flat-file and stick the
name and path in the directory, that way you could grab the link right out
of the database and display it.. This approach requires you have a directory
for each user so that they can have files named the same thing, that or you
can put some ID in the file name to identify it's owner (you'll have
directories for each user anyway I would assume).
Good luck!
-Mitch
----- Original Message -----
From: "Justin Long" <justinlong@strategicnetwork.org>
To: "Pgsql-Php" <pgsql-php@postgresql.org>
Sent: Tuesday, November 28, 2000 9:48 AM
Subject: RE: [PHP] Question re large objects
> The tuple limit is the reason why we created a function for writing large
> text files to a database. Here's the function we use:
>
> function inject($id, $text) {
> // this function splits the article, $text, into 4k chunks and stores it.
> global $db;
> $rs = db_exec("SELECT * FROM article WHERE textid LIKE '$id-%'"); // check
> to see if the text exists
> if ($rs) {
> db_exec("DELETE FROM article WHERE textid LIKE '$id-%'"); // delete old
> text if it does
> }
> $row=1;
> $string="";
> while ($text != "") {
> if (strlen($text) <= 4096) {
> $string = $text;
> $text = "";
> } else {
> $x = 4096;
> while (substr($text,$x,1) != "\n" && $x > 0) { $x = $x - 1; }
> if ($x==0) {
> $x = 4096;
> while (substr($text,$x,1) != " " && $x > 0) { $x = $x - 1; }
> }
> $string = substr($text,0,$x);
> $text = substr($text,$x+1);
> }
> $string = trim($string);
> if ($string!="") {
> $blockid = $id . "-" . substr("00".$row,-2);
> $len = strlen($id);
> $kbid = str_replace("KB","",$id);
> if (strpos($kbid,":")) { $kbid = substr($kbid,0,strpos($kbid,":")); }
> if (!$kbid) { $string = addslashes($string); }
> if ($len > strlen($kbid)) {
> $sql = "INSERT INTO article (kbid,textid,article) VALUES
> ('$kbid','$blockid','$string')";
> db_exec($sql);
> } else {
> db_exec("INSERT INTO article (textid,article) VALUES
> ('$blockid','$string')");
> }
> }
> $row++;
> }
> }
>
> function retrieve($id) {
> // this function retrieves and concatenates the files.
> $rs = db_exec("SELECT * from article WHERE textid LIKE '$id-%' ORDER BY
> textid"); // check to see if text exists
> if ($rs) {
> $row=0;
> $string="";
> while ($row < pg_numrows($rs)) {
> $rec = pg_fetch_object($rs,$row);
> $string = $string . $rec->article;
> $row++;
> }
> } else {
> $string="";
> }
> return($string);
> }
>
>
> It's likely, with a little bit of tweaking, that these functions could be
> used to store image files?
>
> Justin
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-php@postgresql.org
Cc: mitch@venux.net, justinlong@strategicnetwork.org
Subject: Re: Question re large objects
In-Reply-To: <00f901c0596f$c5903c60$0200000a@windows>
References: <PBEMJIMKFNACLPCNPDEBMEMOEHAA.justinlong@strategicnetwork.org> <00f901c0596f$c5903c60$0200000a@windows>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox