Hi all,

After my question yesterday I am not that much further.
The problem was: how to get an uploaded file in a BLOB database field. Or
better: a bytea field, as the database is Postgres.

So far, I have the following:

$NewFileName = "pr_".$ProtocolNr."_".$PK.$Extension;    // $PK the value of the
primary key of the table containing references to uploaded files
$Path = $PhotoDir.$NewFileName;
if (move_uploaded_file($_FILES[$taAttachments->FileName]["tmp_name"],
$Path)) {
   make_thumbnail($NewFileName, $PhotoDir, $ThumbDir, $ThumbSize);
   if (is_file($Path)) {
        // update the table
        $Query = "UPDATE ".$taAttachments->Table." SET
".$taAttachments->FileName."='".NewFileName."' WHERE
".$taAttachments->PK."=".$PK;
        $Result = update_data($Query); // procedure taking care of executing an
update query
        // and insert the image into a special table for temporary archiving of
BLOBS
        $Query = "INSERT INTO ".$taAttachBlobs->Table."
(".$taAttachBlobs->FK_Attach.", ".$taAttachBlobs->Blob.") VALUES (".$PK.",
'".pg_escape_bytea(readfile($Path))."'::bytea)";
        insert_data($Query);  // procedure taking care of executing an insert 
query
   }
}

However, running this code results in having the data to be inserted in the
BLOB echoed to output, and instead of the binary data, the filesize is
stored in the BLOB field.

This makes sense as the manual says:
"int readfile ( string filename [, bool use_include_path [, resource
context]])
Reads a file and writes it to the output buffer.
Returns the number of bytes read from the file."

But then how do I go about getting the binary content of the file inserted
in my SQL statement?

There MUST be someone here who did this already, any hints of how to read
the contents of a local (image) file into a Query that is being constructed
will be appreciated.

(Info on how and why of storing an uploaded file BOTH to the webserver
filesystem AND to a temporarily existing record in a database table might
read my previous post on this).

Marc



Community email addresses:
  Post message: [email protected]
  Subscribe:    [EMAIL PROTECTED]
  Unsubscribe:  [EMAIL PROTECTED]
  List owner:   [EMAIL PROTECTED]

Shortcut URL to this page:
  http://groups.yahoo.com/group/php-list 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-list/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to