function molecule_image($params) { header("Content-type: image/PNG"); include "../config/config.php"; $chembl_id = $params[0]; $image_not_found_file = "{$app2base}/static/images/app/inf.png"; // Double check CHEMBL ID format if (preg_match("/^chembl\\d+\$/i", $chembl_id, $matches) == 0) { header('Content-Length: ' . filesize($image_not_found_file)); readfile($image_not_found_file); exit(0); } // Get image from database $db = pg_connect("user={$db_user} dbname={$db_name} host={$db_host} port={$db_port}"); $sqlImage = "SELECT mp.image from mol_pictures mp, molecule_dictionary md where md.molregno=mp.molregno and md.chembl_id=upper('{$chembl_id}')"; $result_p = pg_query($db, $sqlImage); $row = pg_fetch_array($result_p); // Print image if ($row) { print pg_unescape_bytea($row[image]); } else { header('Content-Length: ' . filesize($image_not_found_file)); readfile($image_not_found_file); exit(0); } }
function get_image_by_imageid($imageid) { /*global $DB; $st = sqlite3_query($DB['DB'], 'select * from images where imageid='.$imageid); info(implode(',',sqlite3_fetch_array($st))); info(sqlite3_column_type($st,3)); info(SQLITE3_INTEGER.','.SQLITE3_FLOAT.','.SQLITE3_TEXT.','.SQLITE3_BLOB.','.SQLITE3_NULL); return 0;*/ global $DB; $result = DBselect('select * from images where imageid=' . $imageid); $row = DBfetch($result); if ($row) { if ($DB['TYPE'] == "ORACLE") { if (!isset($row['image'])) { return 0; } $row['image'] = $row['image']->load(); } else { if ($DB['TYPE'] == "POSTGRESQL") { $row['image'] = pg_unescape_bytea($row['image']); } else { if ($DB['TYPE'] == "SQLITE3") { $row['image'] = pack('H*', $row['image']); } } } return $row; } else { return 0; } }
public function execute($bindValues = array(), $additionalParameters = array(), $query = null) { $query = $this->getQuery(); if (!empty($this->binaries)) { for ($i = 0, $c = count($this->binaries); $i < $c; $i++) { $query = str_replace("__sbl_binary" . ($i + 1), $this->binaries[$i]->getData(), $query); } } $result = parent::execute($bindValues, $additionalParameters, $query); if (!$this->isSelect() || empty($result)) { return $result; } $binaryColumns = array(); foreach ($this->metadata->getColumns() as $column) { if ($column->isBinary()) { $binaryColumns[] = $column->name; } } if (!empty($binaryColumns)) { foreach ($result as &$row) { foreach ($binaryColumns as $colName) { if (isset($row[$colName])) { $row[$colName] = pg_unescape_bytea($row[$colName]); } } } } return $result; }
/** * @param String str * @return String */ public function stripSlashesBinary($str) { if ($this->postgreDbVersion < 9) { return pg_unescape_bytea($str); } return hex2bin(substr($str, 2)); }
/** * fetches next row into this objects var's * * Note: it is ovverridden to deal with automatic unescaping of blob data on pgsql, * also dealing with the MDB2_PORTABILITY_RTRIM option which needs to be disabled * in order to retrieve correct binary data * * @access public * @return boolean on success */ function fetch() { $oDbh =& $this->getDatabaseConnection(); if (empty($oDbh)) { return false; } // When using PgSQL we need to disable MDB2_PORTABILITY_RTRIM portability option if ($pgsql = $oDbh->dbsyntax == 'pgsql') { $portability = $oDbh->getOption('portability'); if ($rtrim = $portability & MDB2_PORTABILITY_RTRIM) { $oDbh->setOption('portability', $portability ^ MDB2_PORTABILITY_RTRIM); } } // Fetch result $result = parent::fetch(); // Reset portability options, in case they have been modified if ($pgsql && $rtrim) { $oDbh->setOption('portability', $portability); } // Unescape data on PgSQL if ($pgsql && $result) { $this->contents = pg_unescape_bytea($this->contents); } return $result; }
public static function getFilePath($oid, $postfix = "picture.jpg") { $file = 'app/cache/file/' . $oid . "_{$postfix}"; $model = PgFileStore::getModel(); $data = $model->getWithField("object_id", $oid); file_put_contents($file, pg_unescape_bytea($data[0]["data"])); return $file; }
function db_stripslashesbinary($str) { global $postgreDbVersion; if( $postgreDbVersion < 9 ) return pg_unescape_bytea($str); return hex2bin( substr($str, 2) ); }
function _unquote($s) { if (USE_BYTEA) { return pg_unescape_bytea($s); } else { return base64_decode($s); } }
function binary_unsql($bin) { if (is_resource($bin)) { $bin = stream_get_contents($bin); } if (DB::connection() instanceof \Illuminate\Database\PostgresConnection) { return pg_unescape_bytea($bin); } return $bin; }
function profile_picture($netid) { init_db(); $query = "SELECT * FROM images WHERE (netid='" . pg_escape_string($netid) . "' AND profile=true) OR image_id='1' ORDER BY image_id DESC"; $results = pg_query($query); $raw_img = pg_unescape_bytea(pg_fetch_result($results, 0, "image")); pg_free_result($results); header("Content-type: image/jpeg"); print $raw_img; }
private function fetch_next() { $row = pg_fetch_assoc($this->result); if ($this->blobs) { foreach ($this->blobs as $blob) { $row[$blob] = pg_unescape_bytea($row[$blob]); } } return $row; }
function zbx_unescape_image($image) { global $DB; $result = $image ? $image : 0; if ($DB['TYPE'] == ZBX_DB_POSTGRESQL) { $result = pg_unescape_bytea($image); } elseif ($DB['TYPE'] == ZBX_DB_SQLITE3) { $result = pack('H*', $image); } return $result; }
function _unquote($s) { if (USE_BYTEA) { return pg_unescape_bytea($s); } if (function_exists('pg_escape_string')) { return $s; } else { return base64_decode($s); } }
public function unserialize($data) { $data = stream_get_contents($data); if (substr($data, 0, 4) != 'SERG') { return $data; } if (!$this->pdo_enabled) { $data = pg_unescape_bytea($data); } return parent::unserialize($data); }
function zbx_unescape_image($image) { global $DB; $result = $image ? $image : 0; if ($DB['TYPE'] == "POSTGRESQL") { $result = pg_unescape_bytea($image); } else { if ($DB['TYPE'] == "SQLITE3") { $result = pack('H*', $image); } } return $result; }
function getImages() { global $conn; $query = "SELECT image FROM readings WHERE image IS NOT NULL"; $result = pg_exec($conn, $query); $index = 0; while ($row = pg_fetch_assoc($result)) { // loop to store the data in an associative array. $derp[$index] = "data:image/jpeg;base64," . base64_encode(pg_unescape_bytea($row["image"])); $index++; } return $derp; //use pg_unescape_bytea to convert image to unescaped first // use imagecreatefromstring afterwards }
private function fetch_next() { if (!$this->result) { return false; } if (!($row = pg_fetch_assoc($this->result))) { pg_free_result($this->result); $this->result = null; return false; } if ($this->blobs) { foreach ($this->blobs as $blob) { $row[$blob] = $row[$blob] !== null ? pg_unescape_bytea($row[$blob]) : null; } } return $row; }
function auth_token_retrieve($scope, $token) { $data = db_getOne(' select data from token where scope = ? and token = ?', array($scope, $token)); /* Madness. We have to unescape this, because the PEAR DB library isn't * smart enough to spot BYTEA columns and do it for us. */ $data = pg_unescape_bytea($data); $pos = 0; $res = rabx_wire_rd(&$data, &$pos); if (rabx_is_error($res)) { $res = unserialize($data); if (is_null($res)) { err("Data for scope '{$scope}', token '{$token}' are not valid"); } } return $res; }
function test_postgis($name, $type, $geom, $connection, $format) { global $table; // Let's insert into the database using GeomFromWKB $insert_string = pg_escape_bytea($geom->out($format)); pg_query($connection, "INSERT INTO {$table} (name, type, geom) values ('{$name}', '{$type}', GeomFromWKB('{$insert_string}'))"); // SELECT using asBinary PostGIS $result = pg_fetch_all(pg_query($connection, "SELECT asBinary(geom) as geom FROM {$table} WHERE name='{$name}'")); foreach ($result as $item) { $wkb = pg_unescape_bytea($item['geom']); // Make sure to unescape the hex blob $geom = geoPHP::load($wkb, $format); // We now a full geoPHP Geometry object } // SELECT and INSERT directly, with no wrapping functions $result = pg_fetch_all(pg_query($connection, "SELECT geom as geom FROM {$table} WHERE name='{$name}'")); foreach ($result as $item) { $wkb = pack('H*', $item['geom']); // Unpacking the hex blob $geom = geoPHP::load($wkb, $format); // We now have a geoPHP Geometry // Let's re-insert directly into postGIS // We need to unpack the WKB $unpacked = unpack('H*', $geom->out($format)); $insert_string = $unpacked[1]; pg_query($connection, "INSERT INTO {$table} (name, type, geom) values ('{$name}', '{$type}', '{$insert_string}')"); } // SELECT and INSERT using as EWKT (ST_GeomFromEWKT and ST_AsEWKT) $result = pg_fetch_all(pg_query($connection, "SELECT ST_AsEWKT(geom) as geom FROM {$table} WHERE name='{$name}'")); foreach ($result as $item) { $wkt = $item['geom']; // Make sure to unescape the hex blob $geom = geoPHP::load($wkt, 'ewkt'); // We now a full geoPHP Geometry object // Let's re-insert directly into postGIS $insert_string = $geom->out('ewkt'); pg_query($connection, "INSERT INTO {$table} (name, type, geom) values ('{$name}', '{$type}', ST_GeomFromEWKT('{$insert_string}'))"); } }
/** * General type conversion method * * @param mixed $value refernce to a value to be converted * @param string $type specifies which type to convert to * @param boolean $rtrim [optional] when TRUE [default], apply rtrim() to text * @return object a MDB2 error on failure * @access protected */ function _baseConvertResult($value, $type, $rtrim = true) { if (is_null($value)) { return null; } switch ($type) { case 'boolean': return $value == 't'; case 'float': return doubleval($value); case 'date': return $value; case 'time': return substr($value, 0, strlen('HH:MM:SS')); case 'timestamp': return substr($value, 0, strlen('YYYY-MM-DD HH:MM:SS')); case 'blob': $value = pg_unescape_bytea($value); return parent::_baseConvertResult($value, $type, $rtrim); } return parent::_baseConvertResult($value, $type, $rtrim); }
function pessoa_foto($id, $curso_id = 0) { require_once dirname(__FILE__) . '/../config/configuracao.php'; require_once $BASE_DIR . 'core/login/session.php'; require_once $BASE_DIR . 'core/web_diario.php'; $session = new session($param_conn); // PROTEGE A FOTO DE ACESSO N�O AUTORIZADO $acessa_foto = FALSE; $usuario = (string) $_SESSION['sa_auth']; if (!empty($usuario)) { $acessa_foto = TRUE; } // ^ PROTEGE A FOTO DE ACESSO N�O AUTORIZADO ^ $image = file_get_contents($BASE_DIR . '/public/images/user.gif'); if (isset($id) && is_numeric($id)) { $db = pg_connect(' host =' . $param_conn['host'] . ' port =' . $param_conn['port'] . ' dbname =' . $param_conn['database'] . ' user ='******'user'] . ' password ='******'password']); // VERIFICA O DIREITO DE ACESSO A FICHA COMO PROFESSOR OU COORDENADOR if (isset($_SESSION['sa_modulo']) && $_SESSION['sa_modulo'] == 'web_diario_login') { $acessa_foto = acessa_ficha_aluno($id, $sa_ref_pessoa, $curso_id, $db); } // ^ VERIFICA O DIREITO DE ACESSO A FICHA COMO PROFESSOR OU COORDENADOR ^ // if ($acessa_foto == TRUE) { $sql = 'SELECT foto FROM pessoas_fotos WHERE ref_pessoa = ' . $_GET['id'] . '; '; $rs = pg_query($db, $sql); $numrows = pg_numrows($rs); if ($numrows != 0) { $image = pg_unescape_bytea(pg_fetch_result($rs, 0, 0)); } else { $image = file_get_contents($BASE_DIR . '/public/images/user.gif'); } pg_close($db); } } header("Content-type: image/jpeg"); echo $image; }
public function execute($bindValues = array(), $additionalParameters = array()) { $result = parent::execute($bindValues, $additionalParameters); if (!$this->isSelect() || empty($result)) { return $result; } $binaryColumns = array(); foreach ($this->metadata->getColumns() as $column) { if ($column->isBinary()) { $binaryColumns[] = $column->name; } } if (!empty($binaryColumns)) { foreach ($result as &$row) { foreach ($binaryColumns as $colName) { if (isset($row[$colName])) { $row[$colName] = pg_unescape_bytea($row[$colName]); } } } } return $result; }
protected function inputNotNull($native) { if ('\\x' !== call_user_func(self::$substr, $native, 0, 2)) { return pg_unescape_bytea($native); } else { // http://www.postgresql.org/docs/current/interactive/datatype-binary.html says: // The "hex" format encodes binary data as 2 hexadecimal digits per byte, most significant nibble first. // The entire string is preceded by the sequence \x (to distinguish it from the escape format). // The hexadecimal digits can be either upper or lower case, and whitespace is permitted between digit // pairs (but not within a digit pair nor in the starting \x sequence). $warning = ''; $result = ''; $start = 2; $length = call_user_func(self::$strlen, $native); while ($start < $length) { $start += strspn($native, " \n\r\t", $start); $hexes = strcspn($native, " \n\r\t", $start); if ($hexes > 0) { if ($hexes % 2) { throw new TypeConversionException(sprintf('%s(): expecting even number of hex digits, %d hex digit(s) found', __METHOD__, $hexes)); } // pack() throws a warning, but returns a string nonetheless, so use warnings handler set_error_handler(function ($errno, $errstr) use(&$warning) { $warning = $errstr; return true; }, E_WARNING); $result .= pack('H*', call_user_func(self::$substr, $native, $start, $hexes)); $start += $hexes; restore_error_handler(); if ($warning) { throw new TypeConversionException(sprintf('%s(): %s', __METHOD__, $warning)); } } } return $result; } }
function decodeBlob($b) { if ($b instanceof PostgresBlob) { $b = $b->fetch(); } elseif ($b instanceof Blob) { return $b->fetch(); } return pg_unescape_bytea($b); }
/** * Unescapes a blob coming out of the database * * @param string $value The value to unescape * @return binary The binary data */ private function unescapeBlob($value) { $this->connectToDatabase(); if ($this->extension == 'pgsql') { return pg_unescape_bytea($value); } elseif ($this->extension == 'pdo' && is_resource($value)) { return stream_get_contents($value); } elseif ($this->extension == 'sqlite') { return pack('H*', $value); } else { return $value; } }
/** * Undo ByteField encoding, if needed. Impl specific. * @return string **/ public function unescape_byte_field($bytes) { return pg_unescape_bytea($bytes); }
/** * Unescape binary data obtained from database * * @param string $val * @return string */ function sql_unescape_binary($val) { if ($this->db_host['parsed']['phptype'] == 'pgsql') { return pg_unescape_bytea($val); } else { return $val; } }
/** * Fetches the next row from the current result set * * @return unknown */ function fetchResult() { if ($row = pg_fetch_row($this->results)) { $resultRow = array(); foreach ($row as $index => $field) { list($table, $column) = $this->map[$index]; $type = pg_field_type($this->results, $index); switch ($type) { case 'bool': $resultRow[$table][$column] = $this->boolean($row[$index], false); break; case 'binary': case 'bytea': $resultRow[$table][$column] = pg_unescape_bytea($row[$index]); break; default: $resultRow[$table][$column] = $row[$index]; break; } } return $resultRow; } else { return false; } }
function _decode($blob) { if ($blob === NULL) { return NULL; } // eval('$realblob="'.adodb_str_replace(array('"','$'),array('\"','\$'),$blob).'";'); return pg_unescape_bytea($blob); }
/** * Reverts a ByteA escape to raw binary * * @param $string The string to clean up * @return The cleaned-up string */ function unescapeBinaryString($string) { return pg_unescape_bytea($string); }