本文整理汇总了PHP中gztell函数的典型用法代码示例。如果您正苦于以下问题:PHP gztell函数的具体用法?PHP gztell怎么用?PHP gztell使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gztell函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: extract_file_from_tarball
function extract_file_from_tarball($pkg, $filename, $dest_dir)
{
global $packages;
$name = $pkg . '-' . $packages[$pkg];
$tarball = $dest_dir . "/" . $name . '.tgz';
$filename = $name . '/' . $filename;
$destfilename = $dest_dir . "/" . basename($filename);
$fp = gzopen($tarball, 'rb');
$done = false;
do {
/* read the header */
$hdr_data = gzread($fp, 512);
if (strlen($hdr_data) == 0) {
break;
}
$checksum = 0;
for ($i = 0; $i < 148; $i++) {
$checksum += ord($hdr_data[$i]);
}
for ($i = 148; $i < 156; $i++) {
$checksum += 32;
}
for ($i = 156; $i < 512; $i++) {
$checksum += ord($hdr_data[$i]);
}
$hdr = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $hdr_data);
$hdr['checksum'] = octdec(trim($hdr['checksum']));
if ($hdr['checksum'] != $checksum) {
echo "Checksum for {$tarball} {$hdr['filename']} is invalid\n";
print_r($hdr);
return;
}
$hdr['size'] = octdec(trim($hdr['size']));
echo "File: {$hdr['filename']} {$hdr['size']}\n";
if ($filename == $hdr['filename']) {
echo "Found the file we want\n";
$dest = fopen($destfilename, 'wb');
$x = stream_copy_to_stream($fp, $dest, $hdr['size']);
fclose($dest);
echo "Wrote {$x} bytes into {$destfilename}\n";
break;
}
/* skip body of the file */
$size = 512 * ceil((int) $hdr['size'] / 512);
echo "Skipping {$size} bytes\n";
gzseek($fp, gztell($fp) + $size);
} while (!$done);
}
示例2: _getOffset
function _getOffset($p_len = null)
{
$ofset = null;
if (is_resource($this->_file)) {
if ($p_len === null) {
$p_len = 512;
}
if ($this->_compress_type == 'gz') {
$ofset = @gztell($this->_file) / $p_len;
} else {
if ($this->_compress_type == 'bz2') {
// ----- Replace missing bztell() and bzseek()
$ofset = 0;
} else {
if ($this->_compress_type == 'none') {
$ofset = @ftell($this->_file) / $p_len;
} else {
$this->_error('Unknown or missing compression type (' . $this->_compress_type . ')');
}
}
}
}
return floor($ofset);
}
示例3: SQLError
SQLError($sqlCommand, $sqlError);
$restore['restore_in_progress'] = 0;
die;
// TODO clean end of process - last message is not
// logged on restore screen and
// not sent back to client. Flag missing here that
// should be handled via JSON
}
}
}
}
}
$timeElapsed = time() - $restore['page_start_time'];
}
if ($restore['compressed']) {
$restore['offset'] = gztell($restore['filehandle']);
gzclose($restore['filehandle']);
} else {
$restore['offset'] = ftell($restore['filehandle']);
fclose($restore['filehandle']);
}
$restore['page_refreshs']++;
// progress of actual file
if ($restore['compressed']) {
// compressed backup - there is no way to get the exact file offset,
// because gztell delivers uncompressed bytes
// so we assume the average packing factor is 11 and will divide the file
// offset by it
$restore['progress_file_percent'] = $restore['offset'] / 11 * 100 / $filesize;
if ($restore['progress_file_percent'] > 100) {
$restore['progress_file_percent'] = 100;
示例4: gzopen
<?php
$f = "temp3.txt.gz";
$h = gzopen($f, 'w');
$str1 = "This is the first line.";
$str2 = "This is the second line.";
gzwrite($h, $str1);
echo "tell=";
var_dump(gztell($h));
//seek to the end which is not sensible of course.
echo "move to the end of the file\n";
var_dump(gzseek($h, 0, SEEK_END));
echo "tell=";
var_dump(gztell($h));
gzwrite($h, $str2);
echo "tell=";
var_dump(gztell($h));
gzclose($h);
echo "\nreading the output file\n";
$h = gzopen($f, 'r');
gzpassthru($h);
gzclose($h);
echo "\n";
unlink($f);
?>
===DONE===
示例5: _jumpBlock
function _jumpBlock($p_len = null)
{
if (is_resource($this->_file)) {
if ($p_len === null) {
$p_len = 1;
}
if ($this->_compress_type == 'gz') {
@gzseek($this->_file, @gztell($this->_file) + $p_len * 512);
} else {
if ($this->_compress_type == 'bz2') {
// ----- Replace missing bztell() and bzseek()
for ($i = 0; $i < $p_len; $i++) {
$this->_readBlock();
}
} else {
if ($this->_compress_type == 'none') {
@fseek($this->_file, @ftell($this->_file) + $p_len * 512);
} else {
$this->_error('Unknown or missing compression type (' . $this->_compress_type . ')');
}
}
}
}
return true;
}
示例6: PclTarHandleUpdate
//.........这里部分代码省略.........
// ----- File name and properties are logged if listing mode or file is extracted
TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '{$v_header['filename']}'");
// ----- Add the array describing the file into the list
$p_list_detail[$v_nb] = $v_header;
$p_list_detail[$v_nb][status] = $v_found_file ? "not_updated" : "ok";
// ----- Increment
$v_nb++;
} else {
// ----- Trace
TrFctMessage(__FILE__, __LINE__, 2, "Start update of file '{$v_current_filename}'");
// ----- Store the old file size
$v_old_size = $v_header[size];
// ----- Add the file
if (($v_result = PclTarHandleAddFile($v_temp_tar, $v_current_filename, $p_tar_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1) {
// ----- Close the tarfile
if ($p_tar_mode == "tar") {
fclose($v_tar);
fclose($v_temp_tar);
} else {
gzclose($v_tar);
gzclose($v_temp_tar);
}
@unlink($p_temp_tarname);
// ----- Return status
TrFctEnd(__FILE__, __LINE__, $v_result);
return $v_result;
}
// ----- Trace
TrFctMessage(__FILE__, __LINE__, 2, "Skip old file '{$v_header['filename']}'");
// ----- Jump to next file
if ($p_tar_mode == "tar") {
fseek($v_tar, ftell($v_tar) + ceil($v_old_size / 512) * 512);
} else {
gzseek($v_tar, gztell($v_tar) + ceil($v_old_size / 512) * 512);
}
// ----- Add the array describing the file into the list
$p_list_detail[$v_nb] = $v_header;
$p_list_detail[$v_nb][status] = "updated";
// ----- Increment
$v_nb++;
}
// ----- Look for end of file
if ($p_tar_mode == "tar") {
$v_end_of_file = feof($v_tar);
} else {
$v_end_of_file = gzeof($v_tar);
}
}
// ----- Look for files that does not exists in the archive and need to be added
for ($i = 0; $i < sizeof($p_file_list); $i++) {
// ----- Look if file not found in the archive
if (!$v_found_list[$i]) {
TrFctMessage(__FILE__, __LINE__, 3, "File '{$p_file_list[$i]}' need to be added");
// ----- Add the file
if (($v_result = PclTarHandleAddFile($v_temp_tar, $p_file_list[$i], $p_tar_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1) {
// ----- Close the tarfile
if ($p_tar_mode == "tar") {
fclose($v_tar);
fclose($v_temp_tar);
} else {
gzclose($v_tar);
gzclose($v_temp_tar);
}
@unlink($p_temp_tarname);
// ----- Return status
TrFctEnd(__FILE__, __LINE__, $v_result);
示例7: _seek
function _seek($p_flen, $tell = 0)
{
if ($this->_nomf === TarLib::ARCHIVE_DYNAMIC) {
$this->_memdat = substr($this->_memdat, 0, ($tell ? strlen($this->_memdat) : 0) + $p_flen);
} elseif ($this->_comptype == TarLib::COMPRESS_GZIP) {
@gzseek($this->_fp, ($tell ? @gztell($this->_fp) : 0) + $p_flen);
} elseif ($this->_comptype == TarLib::COMPRESS_BZIP) {
@fseek($this->_fp, ($tell ? @ftell($this->_fp) : 0) + $p_flen);
} else {
@fseek($this->_fp, ($tell ? @ftell($this->_fp) : 0) + $p_flen);
}
}
示例8: restoreMySqlDump
/** Restore a mysql dump
*
* @param $DB DB object
* @param $dumpFile dump file
* @param $duree max delay before refresh
**/
function restoreMySqlDump($DB, $dumpFile, $duree)
{
global $DB, $TPSCOUR, $offset, $cpt;
// $dumpFile, fichier source
// $duree=timeout pour changement de page (-1 = aucun)
// Desactivation pour empecher les addslashes au niveau de la creation des tables
// En plus, au niveau du dump on considere qu'on est bon
// set_magic_quotes_runtime(0);
if (!file_exists($dumpFile)) {
echo sprintf(__('File %s not found.'), $dumpFile) . "<br>";
return false;
}
if (substr($dumpFile, -2) == "gz") {
$fileHandle = gzopen($dumpFile, "rb");
} else {
$fileHandle = fopen($dumpFile, "rb");
}
if (!$fileHandle) {
//TRASN: %s is the name of the file
echo sprintf(__('Unauthorized access to the file %s'), $dumpFile) . "<br>";
return false;
}
if ($offset != 0) {
if (substr($dumpFile, -2) == "gz") {
if (gzseek($fileHandle, $offset, SEEK_SET) != 0) {
//erreur
//TRANS: %s is the number of the byte
printf(__("Unable to find the byte %s"), Html::formatNumber($offset, false, 0));
echo "<br>";
return false;
}
} else {
if (fseek($fileHandle, $offset, SEEK_SET) != 0) {
//erreur
//TRANS: %s is the number of the byte
printf(__("Unable to find the byte %s"), Html::formatNumber($offset, false, 0));
echo "<br>";
return false;
}
}
Html::glpi_flush();
}
$formattedQuery = "";
if (substr($dumpFile, -2) == "gz") {
while (!gzeof($fileHandle)) {
current_time();
if ($duree > 0 && $TPSCOUR >= $duree) {
//on atteint la fin du temps imparti
return true;
}
// specify read length to be able to read long lines
$buffer = gzgets($fileHandle, 102400);
// do not strip comments due to problems when # in begin of a data line
$formattedQuery .= $buffer;
if (substr(rtrim($formattedQuery), -1) == ";") {
// Do not use the $DB->query
if ($DB->query($formattedQuery)) {
//if no success continue to concatenate
$offset = gztell($fileHandle);
$formattedQuery = "";
$cpt++;
}
}
}
} else {
while (!feof($fileHandle)) {
current_time();
if ($duree > 0 && $TPSCOUR >= $duree) {
//on atteint la fin du temps imparti
return true;
}
// specify read length to be able to read long lines
$buffer = fgets($fileHandle, 102400);
// do not strip comments due to problems when # in begin of a data line
$formattedQuery .= $buffer;
if (substr(rtrim($formattedQuery), -1) == ";") {
// Do not use the $DB->query
if ($DB->query($formattedQuery)) {
//if no success continue to concatenate
$offset = ftell($fileHandle);
$formattedQuery = "";
$cpt++;
}
}
}
}
if ($DB->error) {
echo "<hr>";
//TRANS: %s is the SQL query which generates the error
printf(__("SQL error starting from %s"), "[{$formattedQuery}]");
echo "<br>" . $DB->error() . "<hr>";
}
if (substr($dumpFile, -2) == "gz") {
gzclose($fileHandle);
//.........这里部分代码省略.........
示例9: Skip
function Skip($Block = 0)
{
if (!$Block)
return false;
$pos = $this->gzip ? gztell($this->res) : ftell($this->res);
if (file_exists($this->getNextName()))
{
while(($BlockLeft = ($this->getArchiveSize($this->file) - $pos)/512) < $Block)
{
if ($BlockLeft != floor($BlockLeft))
return false; // invalid file size
$this->Block += $BlockLeft;
$Block -= $BlockLeft;
if (!$this->openNext())
return false;
$pos = 0;
}
}
$this->Block += $Block;
return 0 === ($this->gzip ? gzseek($this->res,$pos + $Block*512) : fseek($this->res,$pos + $Block*512));
}
示例10: tell
public function tell()
{
if (is_null($this->handle))
{
return false;
}
return gztell($this->handle);
}
示例11: gzencode
$zipped = gzencode("testing gzencode");
VS(gzdecode($zipped), "testing gzencode");
$f = gzopen($tmpfile, "w");
VERIFY($f !== false);
gzputs($f, "testing gzputs\n");
gzwrite($f, "<html>testing gzwrite</html>\n");
gzclose($f);
$f = gzopen($tmpfile, "r");
VS(gzread($f, 7), "testing");
VS(gzgetc($f), " ");
VS(gzgets($f), "gzputs\n");
VS(gzgetss($f), "testing gzwrite\n");
VS(gztell($f), 44);
VERIFY(gzeof($f));
VERIFY(gzrewind($f));
VS(gztell($f), 0);
VERIFY(!gzeof($f));
gzseek($f, -7, SEEK_END);
VS(gzgets($f), "testing gzputs\n");
gzclose($f);
$f = gzopen(__DIR__ . "/test_ext_zlib.gz", "r");
gzpassthru($f);
$compressable = str_repeat('A', 1024);
$s = $compressable;
$t = nzcompress($s);
VERIFY(strlen($t) < strlen($s));
$u = nzuncompress($t);
VS($u, $s);
$compressable = str_repeat('\\0', 1024);
$bs = $compressable;
$bt = nzcompress($bs);
示例12: tell
/**
* Returns the current position of the file read/write pointer.
*
* @return mixed
*
* @since 1.0
* @throws \RuntimeException
*/
public function tell()
{
if (!$this->fh) {
throw new \RuntimeException('File not open');
}
// Capture PHP errors
$php_errormsg = '';
$track_errors = ini_get('track_errors');
ini_set('track_errors', true);
switch ($this->processingmethod) {
case 'gz':
$res = gztell($this->fh);
break;
case 'bz':
case 'f':
default:
$res = ftell($this->fh);
break;
}
// May return 0 so check if it's really false
if ($res === false) {
throw new \RuntimeException($php_errormsg);
}
// Restore error tracking to what it was before
ini_set('track_errors', $track_errors);
// Return the result
return $res;
}
示例13: restoreMySqlDump_old
function restoreMySqlDump_old($dumpFile, $duree)
{
// $dumpFile, fichier source
// $duree=timeout pour changement de page (-1 = aucun)
global $TPSCOUR, $offset, $cpt, $erreur_mysql;
if (!file_exists($dumpFile)) {
echo "{$dumpFile} non trouvé<br />\n";
return FALSE;
}
$fileHandle = gzopen($dumpFile, "rb");
if (!$fileHandle) {
echo "Ouverture de {$dumpFile} impossible.<br />\n";
return FALSE;
}
if ($offset != 0) {
if (gzseek($fileHandle, $offset, SEEK_SET) != 0) {
//erreur
echo "Impossible de trouver l'octet " . number_format($offset, 0, "", " ") . "<br />\n";
return FALSE;
}
flush();
}
$formattedQuery = "";
$old_offset = $offset;
while (!gzeof($fileHandle)) {
current_time();
if ($duree > 0 and $TPSCOUR >= $duree) {
//on atteint la fin du temps imparti
if ($old_offset == $offset) {
echo "<p class=\"rouge center\"><strong>La procédure de restauration ne peut pas continuer.\n <br />Un problème est survenu lors du traitement d'une requête près de :.\n <br />" . $debut_req . "</strong></p><hr />\n";
return FALSE;
}
$old_offset = $offset;
return TRUE;
}
//echo $TPSCOUR."<br />";
$buffer = gzgets($fileHandle);
if (mb_substr($buffer, mb_strlen($buffer), 1) == 0) {
$buffer = mb_substr($buffer, 0, mb_strlen($buffer) - 1);
}
//echo $buffer."<br />";
if (mb_substr($buffer, 0, 1) != "#" and mb_substr($buffer, 0, 1) != "/") {
if (!isset($debut_req)) {
$debut_req = $buffer;
}
$formattedQuery .= $buffer;
//echo $formattedQuery."<hr />";
if (trim($formattedQuery) != "") {
$sql = $formattedQuery;
if (mysqli_query($GLOBALS["mysqli"], $sql)) {
//réussie sinon continue à concaténer
$offset = gztell($fileHandle);
//echo $offset;
$formattedQuery = "";
unset($debut_req);
$cpt++;
//echo "$cpt requêtes exécutées avec succès jusque là.<br />";
}
}
}
}
if (mysqli_error($GLOBALS["mysqli"])) {
echo "<hr />\nERREUR à partir de " . nl2br($formattedQuery) . "<br />" . mysqli_error($GLOBALS["mysqli"]) . "<hr />\n";
$erreur_mysql = TRUE;
}
gzclose($fileHandle);
$offset = -1;
return TRUE;
}
示例14: dirname
<?php
$f = dirname(__FILE__) . "/004.txt.gz";
$h = gzopen($f, 'r');
$extra_arg = 'nothing';
var_dump(gztell($h, $extra_arg));
var_dump(gztell());
gzclose($h);
?>
===DONE===
示例15: skipFile
function skipFile($zh, $size)
{
gzseek($zh, gztell($zh) + ceil($size / 512) * 512);
}