Storing any files (binary as well as ASCII) to postgres
db destroys them
i am able to upload files into a postgres db but when i
download them they are destroyed.
Following links might help:
http://www.php.net/manual/en/function.file-get-contents.php
http://www.php.net/manual/en/function.pg-escape-bytea.php
http://www.php.net/manual/en/function.pg-escape-string.php
http://www.php.net/manual/en/function.pg-query.php
Folling hint might help for an generic solution:
use base64encode on binaries and shove them in a text field
Logged In: YES
user_id=55225
Convert these to OWL:
function createBlob( $conn, $id, $blob ) {
$index = 0;
$row = 0;
$blob = base64_encode($blob);
pg_exec( $conn, "begin work" );
while ( $index < strlen($blob) ) :
pg_exec( $conn, "insert into blobs (id,part,data) values " .
"(".$id.",".$row.",'".addSlashes(substr($blob,$index,4096))."')"
);
$index += 4096;
$row++;
endwhile;
pg_exec( $conn, "commit work" );
}
function createBlobFromFile( $conn, $id, $fileName ) {
$fd = fopen($fileName,"r");
$blob = fread($fd,filesize($fileName));
fclose( $fd );
createBlob( $conn, $id, $blob );
}
function getBlob( $conn, $id ) {
$result = pg_exec($conn,"select * from blobs where
d=".$id." order by part");
$blob = "";
for ( $row=0; $row<pg_numRows($result); $row++ ) :
$data = pg_fetch_object($result,$row);
$blob .= $data->data;
endfor;
$blob = base64_decode($blob);
return $blob;
}
function deleteBlob( $conn, $id ) {
$result = pg_exec($conn,"delete from blobs where id=".$id);
}
function updateBlob( $conn, $id, $blob ) {
deleteBlob( $conn, $id );
createBlob( $conn, $id, $blob );
}
function updateBlobFromFile( $conn, $id, $fileName ) {
deleteBlob( $conn, $id );
createBlobFromFile( $conn, $id, $fileName );
}
http://builder.com.com/5110-6388-1050894.html
B0zz