本文整理汇总了PHP中gzread函数的典型用法代码示例。如果您正苦于以下问题:PHP gzread函数的具体用法?PHP gzread怎么用?PHP gzread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gzread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: animetitlesUpdate
public function animetitlesUpdate()
{
$pdo = $this->pdo;
$lastUpdate = $pdo->queryOneRow('SELECT max(unixtime) as utime FROM animetitles');
if (isset($lastUpdate['utime']) && time() - $lastUpdate['utime'] < 604800) {
if ($this->echooutput) {
echo "\n";
echo $this->c->info("Last update occurred less than 7 days ago, skipping full dat file update.\n\n");
}
return;
}
if ($this->echooutput) {
echo $this->c->header("Updating animetitles by grabbing full dat AniDB dump.\n\n");
}
$zh = gzopen('http://anidb.net/api/anime-titles.dat.gz', 'r');
preg_match_all('/(\\d+)\\|\\d\\|.+\\|(.+)/', gzread($zh, '10000000'), $animetitles);
if (!$animetitles) {
return false;
}
$pdo->queryExec('DELETE FROM animetitles WHERE anidbid IS NOT NULL');
if ($this->echooutput) {
echo $this->c->header("Total of " . count($animetitles[1]) . " titles to add\n\n");
}
for ($loop = 0; $loop < count($animetitles[1]); $loop++) {
$pdo->queryInsert(sprintf('INSERT IGNORE INTO animetitles (anidbid, title, unixtime) VALUES (%d, %s, %d)', $animetitles[1][$loop], $pdo->escapeString(html_entity_decode($animetitles[2][$loop], ENT_QUOTES, 'UTF-8')), time()));
}
if ($loop % 2500 == 0 && $this->echooutput) {
echo $this->c->header("Completed Processing " . $loop . " titles.\n\n");
}
gzclose($zh);
if ($this->echooutput) {
echo $this->c->header("Completed animetitles update.\n\n");
}
}
示例2: readCompressedSample
public function readCompressedSample($filename)
{
$fp = gzopen('test/samples/' . $filename, 'r') or die("can't open: {$php_errormsg}");
$content = gzread($fp, 128000);
gzclose($fp);
return $content;
}
示例3: extract
public function extract($archive="", $outputDir = "")
{
$gzh = gzopen($archive, 'r') or die("Could not open $archive");
if(!is_dir($outputDir))
{
mkdir($outputDir, 0700, true) or die("Could not create a $outputDir directory");
}
$_archive = str_ireplace('.tgz', '.gz', $archive);
$tar_path = basename($_archive, '.gz');
$lchar = substr($outputDir, -1);
if('/' == $lchar OR '\\' == $lchar)
{
$tar_path = $outputDir.$tar_path;
} else {
$tar_path = $outputDir."/".$tar_path;
}
$fh = fopen($tar_path, "w");
while(!feof($gzh))
{
$cstr = gzread($gzh, 4096);
fwrite($fh, $cstr);
}
bzclose($gzh);
fclose($fh);
$this->tarHandler->extract($tar_path, $outputDir);
echo "<font color=\"green\">Sucessfull!</font>";
}
示例4: backwpup_read_logheader
function backwpup_read_logheader($logfile)
{
$headers = array("backwpup_version" => "version", "backwpup_logtime" => "logtime", "backwpup_errors" => "errors", "backwpup_warnings" => "warnings", "backwpup_jobid" => "jobid", "backwpup_jobname" => "name", "backwpup_jobtype" => "type", "backwpup_jobruntime" => "runtime", "backwpup_backupfilesize" => "backupfilesize");
if (!is_readable($logfile)) {
return false;
}
//Read file
if (substr($logfile, -3) == ".gz") {
$fp = gzopen($logfile, 'r');
$file_data = gzread($fp, 1536);
// Pull only the first 1,5kiB of the file in.
gzclose($fp);
} else {
$fp = fopen($logfile, 'r');
$file_data = fread($fp, 1536);
// Pull only the first 1,5kiB of the file in.
fclose($fp);
}
//get data form file
foreach ($headers as $keyword => $field) {
preg_match('/(<meta name="' . $keyword . '" content="(.*)" \\/>)/i', $file_data, $content);
if (!empty($content)) {
$joddata[$field] = $content[2];
} else {
$joddata[$field] = '';
}
}
if (empty($joddata['logtime'])) {
$joddata['logtime'] = filectime($logfile);
}
return $joddata;
}
示例5: __parseLog
protected function __parseLog($file)
{
$items = array();
$last = null;
if (is_readable($file)) {
header('content-type: text/plain');
if (preg_match('/.gz$/', $file)) {
$handle = gzopen($file, "r");
$data = gzread($handle, Symphony::Configuration()->get('maxsize', 'log'));
gzclose($handle);
} else {
$data = file_get_contents($file);
}
$lines = explode(PHP_EOL, $data);
// Skip log info:
while (count($lines)) {
$line = trim(array_shift($lines));
if ($line == '--------------------------------------------') {
break;
}
}
// Create items:
foreach ($lines as $line) {
preg_match('/^(.*?) > (.*)/', trim($line), $matches);
// New entry:
if (count($matches) == 3) {
$message = htmlentities($matches[2]);
$items[] = (object) array('timestamp' => DateTimeObj::get(__SYM_DATETIME_FORMAT__, strtotime($matches[1])), 'message' => $message);
}
}
// Reverse order:
$items = array_reverse($items);
}
return $items;
}
示例6: update_database
public static function update_database()
{
set_time_limit(0);
$outFile = self::get_upload_file_path();
// for download_url()
require_once ABSPATH . 'wp-admin/includes/file.php';
$tmpFile = \download_url(self::SOURCE_URL);
if (is_wp_error($tmpFile)) {
die($tmpFile->get_error_message());
}
$zh = gzopen($tmpFile, 'rb');
$h = fopen($outFile, 'wb');
if (!$zh) {
die('Downloaded file could not be opened for reading.');
}
if (!$h) {
die(sprintf('Database could not be written (%s).', $outFile));
}
while (!gzeof($zh)) {
fwrite($h, gzread($zh, 4096));
}
gzclose($zh);
fclose($h);
unlink($tmpFile);
if (!self::is_db_valid()) {
die(sprintf('Checksum does not match (%s).', $outFile));
}
}
示例7: animetitlesUpdate
public function animetitlesUpdate()
{
$db = new DB();
$lastUpdate = $db->queryOneRow("SELECT unixtime AS utime FROM animetitles LIMIT 1");
if (isset($lastUpdate['utime']) && time() - $lastUpdate['utime'] < 604800) {
return;
}
if ($this->echooutput) {
echo "Updating animetitles.";
}
$zh = gzopen('http://anidb.net/api/animetitles.dat.gz', 'r');
preg_match_all('/(\\d+)\\|\\d\\|.+\\|(.+)/', gzread($zh, '10000000'), $animetitles);
if (!$animetitles) {
return false;
}
if ($this->echooutput) {
echo ".";
}
$db->query("DELETE FROM animetitles WHERE anidbID IS NOT NULL");
for ($i = 0; $i < count($animetitles[1]); $i++) {
$db->queryInsert(sprintf("INSERT INTO animetitles (anidbID, title, unixtime) VALUES (%d, %s, %d)", $animetitles[1][$i], $db->escapeString(html_entity_decode($animetitles[2][$i], ENT_QUOTES, 'UTF-8')), time()));
}
$db = NULL;
gzclose($zh);
if ($this->echooutput) {
echo " done.\n";
}
}
示例8: geoip_detect_update
function geoip_detect_update()
{
$download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz';
$outFile = geoip_detect_get_database_upload_filename();
// Download
$tmpFile = download_url($download_url);
if (is_wp_error($tmpFile)) {
return $tmpFile->get_error_message();
}
// Ungzip File
$zh = gzopen($tmpFile, 'r');
$h = fopen($outFile, 'w');
if (!$zh) {
return __('Downloaded file could not be opened for reading.', 'geoip-detect');
}
if (!$h) {
return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile);
}
while (($string = gzread($zh, 4096)) != false) {
fwrite($h, $string, strlen($string));
}
gzclose($zh);
fclose($h);
//unlink($tmpFile);
return true;
}
示例9: updateGeoIpFile
/**
* updates the GeoIP database file
* works only if directory geoip has rights 777, set it in ftp client
*/
function updateGeoIpFile()
{
global $cpd_path;
// set directory mode
@chmod($cpd_path . '/geoip', 0777);
// function checks
if (!ini_get('allow_url_fopen')) {
return 'Sorry, <code>allow_url_fopen</code> is disabled!';
}
if (!function_exists('gzopen')) {
return __('Sorry, necessary functions (zlib) not installed or enabled in php.ini.', 'cpd');
}
$gzfile = 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz';
$file = $cpd_path . '/geoip/GeoIP.dat';
// get remote file
$h = gzopen($gzfile, 'rb');
$content = gzread($h, 1500000);
fclose($h);
// delete local file
if (is_file($file)) {
unlink($file);
}
// file deleted?
$del = is_file($file) ? 0 : 1;
// write new locale file
$h = fopen($file, 'wb');
fwrite($h, $content);
fclose($h);
@chmod($file, 0777);
if (is_file($file) && $del) {
return __('New GeoIP database installed.', 'cpd');
} else {
return __('Sorry, an error occurred. Try again or check the access rights of directory "geoip" is 777.', 'cpd');
}
}
示例10: geoip_detect_update
function geoip_detect_update()
{
// TODO: Currently cron is scheduled but not executed. Remove scheduling.
if (get_option('geoip-detect-source') != 'auto') {
return;
}
$download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz';
$download_url = apply_filters('geoip_detect2_download_url', $download_url);
$outFile = geoip_detect_get_database_upload_filename();
// Download
$tmpFile = download_url($download_url);
if (is_wp_error($tmpFile)) {
return $tmpFile->get_error_message();
}
// Ungzip File
$zh = gzopen($tmpFile, 'r');
$h = fopen($outFile, 'w');
if (!$zh) {
return __('Downloaded file could not be opened for reading.', 'geoip-detect');
}
if (!$h) {
return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile);
}
while (($string = gzread($zh, 4096)) != false) {
fwrite($h, $string, strlen($string));
}
gzclose($zh);
fclose($h);
unlink($tmpFile);
return true;
}
示例11: wp_all_import_get_gz
function wp_all_import_get_gz($filename, $use_include_path = 0, $targetDir = false)
{
$type = 'csv';
$uploads = wp_upload_dir();
$targetDir = !$targetDir ? wp_all_import_secure_file($uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::UPLOADS_DIRECTORY) : $targetDir;
$tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
$localPath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
$fp = @fopen($localPath, 'w');
$file = @gzopen($filename, 'rb', $use_include_path);
if ($file) {
$first_chunk = true;
while (!gzeof($file)) {
$chunk = gzread($file, 1024);
if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
$type = 'xml';
$first_chunk = false;
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
@fwrite($fp, $chunk);
}
gzclose($file);
} else {
$tmpname = wp_unique_filename($targetDir, strlen(basename($filename)) < 30 ? basename($filename) : time());
$localGZpath = $targetDir . '/' . urldecode(sanitize_file_name($tmpname));
$request = get_file_curl($filename, $localGZpath, false, true);
if (!is_wp_error($request)) {
$file = @gzopen($localGZpath, 'rb', $use_include_path);
if ($file) {
$first_chunk = true;
while (!gzeof($file)) {
$chunk = gzread($file, 1024);
if ($first_chunk and strpos($chunk, "<?") !== false and strpos($chunk, "</") !== false) {
$type = 'xml';
$first_chunk = false;
}
// if it's a 1st chunk, then chunk <? symbols to detect XML file
@fwrite($fp, $chunk);
}
gzclose($file);
}
@unlink($localGZpath);
} else {
return $request;
}
}
@fclose($fp);
if (preg_match('%\\W(gz)$%i', basename($localPath))) {
if (@rename($localPath, str_replace('.gz', '.' . $type, $localPath))) {
$localPath = str_replace('.gz', '.' . $type, $localPath);
}
} else {
if (@rename($localPath, $localPath . '.' . $type)) {
$localPath = $localPath . '.' . $type;
}
}
return array('type' => $type, 'localPath' => $localPath);
}
示例12: read
function read()
{
if ($this->stream instanceof \IO\Buffer\Stream) {
$length = $this->stream->getLength();
} else {
$length = $this->stream->getFile()->getSize(true);
}
return gzread($this->stream->getPointer(), $length);
}
示例13: main
function main()
{
$fnam = tempnam('/tmp', 'unittest');
$f = fopen('compress.zlib://file://' . $fnam, 'w');
fwrite($f, 'hello, world');
fclose($f);
$f = gzopen($fnam, 'r');
var_dump(gzread($f, 1024));
gzclose($f);
}
示例14: read
public function read($file)
{
$open = gzopen($file, 'r');
if (empty($open)) {
throw new FileNotFoundException('Error', 'fileNotFound', $file);
}
$return = gzread($open, 8096);
gzclose($open);
return $return;
}
示例15: decompressFile
/**
* @param $fileName
* @param $outputFilePath
*/
private function decompressFile($fileName, $outputFilePath)
{
$gz = gzopen($fileName, 'rb');
$outputFile = fopen($outputFilePath, 'wb');
while (!gzeof($gz)) {
fwrite($outputFile, gzread($gz, 4096));
}
fclose($outputFile);
gzclose($gz);
}