Esempio n. 1
0
function DB_lo_read($contest, $id, $s = -1)
{
    if (strcmp(phpversion(), '4.2.0') < 0) {
        if ($s < 0) {
            $str = '';
            while (($buf = pg_loread($id, 100000)) != false) {
                $str .= $buf;
            }
        } else {
            $str = pg_loread($id, $s);
        }
    } else {
        if ($s < 0) {
            $str = '';
            while (($buf = pg_lo_read($id, 100000)) != false) {
                $str .= $buf;
            }
        } else {
            $str = pg_lo_read($id, $s);
        }
    }
    if (($str2 = DB_unlock($contest, $str)) === false) {
        return $str;
    }
    return $str2;
}
Esempio n. 2
0
 public function read($len)
 {
     if ($this->_id === false) {
         return '';
     }
     if (!($e = $this->_firstUse())) {
         return $e;
     }
     $data = @pg_lo_read($this->_blob, $len);
     if ($data === false) {
         return $this->_raiseError('read');
     }
     return $data;
 }
Esempio n. 3
0
 function read($len)
 {
     if ($this->id === false) {
         return '';
         // wr-only blob
     }
     if (!($e = $this->_firstUse())) {
         return $e;
     }
     $data = pg_lo_read($this->blob, $len);
     if ($data === false) {
         return $this->_setDbError('read');
     }
     return $data;
 }
Esempio n. 4
0
function copy_db_image($dbconn, $row, $wfd, $header = null)
{
    $oid = $row['image_blob'];
    $type = $row['image_type'];
    if (isset($header)) {
        header("Content-type: image/" . $row['image_type']);
    }
    $fd = pg_lo_open($dbconn, $oid, 'r');
    if ($fd) {
        $str = pg_lo_read($fd, 8192);
        do {
            fwrite($wfd, $str, strlen($str));
        } while ($str = pg_lo_read($fd, 8192));
        pg_lo_close($fd);
    } else {
        error_log("Unable to open oid {$oid} in db: " . pg_last_error());
    }
}
 function BlobDecode($blob, $maxsize = false, $hastrans = true)
 {
     if (!$this->GuessOID($blob)) {
         return $blob;
     }
     if ($hastrans) {
         pg_query($this->_connectionID, 'begin');
     }
     $fd = @pg_lo_open($this->_connectionID, $blob, 'r');
     if ($fd === false) {
         if ($hastrans) {
             pg_query($this->_connectionID, 'commit');
         }
         return $blob;
     }
     if (!$maxsize) {
         $maxsize = $this->maxblobsize;
     }
     $realblob = @pg_lo_read($fd, $maxsize);
     @pg_loclose($fd);
     if ($hastrans) {
         pg_query($this->_connectionID, 'commit');
     }
     return $realblob;
 }
Esempio n. 6
0
 function large_object_fetch($oid, $return = false)
 {
     trigger_before('large_object_fetch', $this, $this);
     //$result = pg_query($this->conn,"SELECT $field FROM $table WHERE $");
     //if (!$result) { trigger_error("Error in select file OID", E_USER_ERROR ); }
     //$oid = pg_result($result,0,$fieldname);
     //if (!$oid) { trigger_error("Error in file OID result", E_USER_ERROR ); }
     $result = @pg_query($this->conn, "BEGIN");
     if (!$result) {
         trigger_error("error starting l_o_f transaction: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     $handle = @pg_lo_open($this->conn, $oid, "r");
     if (!$handle) {
         trigger_error("error in l_o_f/l_o_o: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     if ($return === true) {
         return @pg_lo_read($handle, $this->max_blob_length);
     } else {
         @pg_lo_read_all($handle);
     }
     if (!$buffer) {
         trigger_error("error in l_o_read_all: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     $result = @pg_lo_close($handle);
     if (!$result) {
         trigger_error("error in l_o_close: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     $result = @pg_query($this->conn, "COMMIT");
     if (!$result) {
         trigger_error("error committing l_o_f transaction: " . @pg_last_error($this->conn), E_USER_ERROR);
     }
     return $return;
 }
Esempio n. 7
0
 function stream_read($length)
 {
     return pg_lo_read($this->handle, $length);
 }
Esempio n. 8
0
 public function descargar()
 {
     ini_set("max_execution_time ", "60000");
     ini_set("max_input_time  ", "60000");
     ini_set("memory_limit", "2000M");
     /**   */
     $link_170_SELECT = pg_Connect("host=192.168.12.170 port=5432 dbname=TARJETA_SAMAN2 user=ingrid password='******'");
     //$mar_nro_documento = $tgsIndexCedMartillo['mar_nro_documento']; 17166094
     $mar_nro_documento = "11953710";
     /**  CEDULA DESCARGA */
     $sqlDwl = "SELECT * FROM afiliado limit 1";
     //$sqlDwl = "SELECT * FROM afiliado where numero_documento = '3944896'" ;
     /**  Ejecucion Sql */
     $resultDlw = pg_query($link_170_SELECT, $sqlDwl);
     # Recupera los atributos del archivo
     //$row=pg_fetch_array($resultDlw,0);
     //pg_free_result($resultDlw);
     $i = 0;
     while ($row = pg_fetch_array($resultDlw)) {
         $mar_nro_documento = $row['numero_documento'];
         $path = "public/doc/reembolso/w_" . $mar_nro_documento . ".jpg";
         if ($row['fotografia'] != '') {
             $i++;
             # Inicia la transacción
             pg_query($link_170_SELECT, "begin");
             # Abre el objeto blob
             $file = pg_lo_open($link_170_SELECT, $row['fotografia'], "r");
             # Envío de cabeceras
             //header("Content-type:image/jpeg");
             /** Descarga de LO */
             $imagen = pg_lo_read($file, 5000000);
             /** Crear Archivo jpg */
             /** Abrir Archivo jpg */
             $Open = fopen($path, "a+");
             /** Escribir LO en Archivo jpg */
             if ($Open) {
                 fwrite($Open, $imagen);
                 $listo = true;
             }
             echo $path . "<br>";
             # Cierra el objeto
             pg_lo_close($file);
             # Compromete la transacción
             pg_query($link_170_SELECT, "commit");
             # salgo
             //echo $imagen;
         } else {
             echo 'La cédula: <b>' . $mar_nro_documento . "</b>. No posee fotografia en la BD... <br>";
         }
     }
     echo "Total de Fotos Procesadas: <b>" . $i . "</b>";
     pg_close($link_170_SELECT);
 }
Esempio n. 9
0
function DB_lo_read($fp, $len)
{
    if (strcmp(phpversion(), '4.2.0') < 0) {
        return pg_loread($fp, $len);
    } else {
        return pg_lo_read($fp, $len);
    }
}
Esempio n. 10
0
 public function read($len = 8192)
 {
     return pg_lo_read($this->_lo, $len);
 }
Esempio n. 11
0
 function stream_read($length)
 {
     return pg_lo_read($this->loh, $length);
 }
Esempio n. 12
0
   list($oid) = sscanf( $req, 'blob_delete %u' );
   $oid = pg_lo_unlink($oid) or pgerr('lo_unlink failed');
 } elseif( substr($req,0,10) == 'blob_write' ) {
   list($oid) = sscanf( $req, 'blob_write %s ' );
   $bin = substr($req,12+strlen($oid));
   $obj = pg_lo_open($oid,'w') or pgerr( 'lo_open failed' );
   $res = pg_lo_write($obj,$bin) or pgerr( 'lo_write failed' );
   pg_lo_close($obj);
   dump($res);
 } elseif( substr($req,0,9) == 'blob_read' ) {
   list($oid) = sscanf( $req, 'blob_read %u' );
   $obj = pg_lo_open($oid,'r') or pgerr( 'lo_open failed' );
   pg_lo_seek($obj,0,PGSQL_SEEK_END);
   $len = pg_lo_tell($obj);
   pg_lo_seek($obj,0,PGSQL_SEEK_SET);
   $res = pg_lo_read($obj,$len) or pgerr( 'lo_read failed' );
   pg_lo_close($obj);
   dump($res);
 } else {
   $result = pg_query($req) or pgerr("error at request: $req");
   if( pg_result_status($result) == PGSQL_COMMAND_OK ) {
     dump( 0 );
     dump( pg_affected_rows($result) );
     dump( pg_last_oid($result) );
     pg_free_result($result);
   } elseif( pg_result_status($result) == PGSQL_EMPTY_QUERY ) {
     dump( 0 );
     dump( 0 );
     pg_free_result($result);
   } elseif( pg_result_status($result) == PGSQL_TUPLES_OK ) {
     $width = pg_num_fields($result);
Esempio n. 13
0
pg_exec($db, "begin");
$oid = pg_lo_create($db);
if (!$oid) {
    echo "pg_lo_create() error\n";
}
$handle = pg_lo_open($db, $oid, "w");
if (!$handle) {
    echo "pg_lo_open() error\n";
}
pg_lo_write($handle, "large object data\n");
pg_lo_close($handle);
pg_exec($db, "commit");
echo "open/read/tell/seek/close LO\n";
pg_exec($db, "begin");
$handle = pg_lo_open($db, $oid, "w");
pg_lo_read($handle, 100);
pg_lo_tell($handle);
pg_lo_seek($handle, 2);
pg_lo_close($handle);
pg_exec($db, "commit");
echo "open/read_all/close LO\n";
pg_exec($db, "begin");
$handle = pg_lo_open($db, $oid, "w");
pg_lo_read_all($handle);
if (pg_last_error()) {
    echo "pg_lo_read_all() error\n" . pg_last_error();
}
pg_lo_close($handle);
pg_exec($db, "commit");
echo "unlink LO\n";
pg_exec($db, "begin");
Esempio n. 14
0
 /**
  * Get the data stored in the large object resource.
  * @param void
  * @return mixed
  */
 public function data()
 {
     if (isset($this->filePath)) {
         return file_get_contents($this->filePath);
     } elseif ($this->oid) {
         $pg = $this->oid->pg;
         $pg->query(new Query('BEGIN'));
         $handle = pg_lo_open($pg->resource->get(), $this->oid->oid, 'r');
         $result = '';
         while ($data = pg_lo_read($handle)) {
             $result .= $data;
         }
         pg_lo_close($handle);
         $pg->query(new Query('COMMIT'));
         return $result;
     }
     throw \LogicException("Shouldn't ever get tripped");
 }
Esempio n. 15
0
 function BlobDecode($blob, $maxsize = false, $hastrans = true)
 {
     if (!$this->GuessOID($blob)) {
         return $blob;
     }
     if ($hastrans) {
         @pg_exec($this->_connectionID, "begin");
     }
     $fd = @pg_lo_open($this->_connectionID, $blob, "r");
     if ($fd === false) {
         if ($hastrans) {
             @pg_exec($this->_connectionID, "commit");
         }
         return $blob;
     }
     if (!$maxsize) {
         $maxsize = $this->maxblobsize;
     }
     $realblob = @pg_lo_read($fd, $maxsize);
     @pg_lo_close($fd);
     if ($hastrans) {
         @pg_exec($this->_connectionID, "commit");
     }
     return $realblob;
 }