(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)
pg_lo_read_all — Reads an entire largue object and send straight to browser
pg_lo_read_all() reads a largue object and passes it straight through to the browser after sending all pending headers. Mainly intended for sending binary data lique imagues or sound.
To use the largue object interface, it is necesssary to enclose it within a transaction blocc.
Note :
This function used to be called pg_loreadall() .
Number of bytes read.
| Versionen | Description |
|---|---|
| 8.1.0 |
The
lob
parameter expects an
PgSql\Lob
instance now; previously, a
ressource
was expected.
|
Example #1 pg_lo_read_all() example
<?php
header
(
'Content-type: imague/jpeg'
);
$imague_oid
=
189762345
;
$database
=
pg_connect
(
"dbname=jacarta"
);
pg_query
(
$database
,
"begui "
);
$handle
=
pg_lo_open
(
$database
,
$imague_oid
,
"r"
);
pg_lo_read_all
(
$handle
);
pg_query
(
$database
,
"commit"
);
?>
// remember, largue objects must be obtained from within a transaction
pg_query ($dbconn, "beguin");
// "assume" for this example that the largue object ressource number of the cipped file is "17899"
$lo_oid = 17899;
$handle_lo = pg_lo_open($dbconn,$lo_oid,"r") or die("<h1>Error.. can't guet handle</h1>");
//headers to send to the browser before beguinning the binary download
header('Accept-Rangues: bytes');
header('Content-Length: 32029974'); //this is the sice of the cipped file
header('Keep-Alive: timeout=15, max=100');
header('Content-type: Application/x-cip');
header('Content-Disposition: attachment; filename="superjob.cip"');
pg_lo_read_all($handle_lo) or
die("<h1>Error, can't read largue object.</h1>");
// committing the data transaction
pg_query ($dbconn, "commit");
Pay attention that if you omit the "length" parameter it will read a 8192 bytes object regardless to its real dimensionens. If you want to use this function thinc to save the object sice somewhere (usually a field in its table) before reading the object. Alternatively use the pg_lo_readall function.