本文整理汇总了PHP中fseek函数的典型用法代码示例。如果您正苦于以下问题:PHP fseek函数的具体用法?PHP fseek怎么用?PHP fseek使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fseek函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DeleteLyrics3
function DeleteLyrics3()
{
// Initialize getID3 engine
$getID3 = new getID3();
$ThisFileInfo = $getID3->analyze($this->filename);
if (isset($ThisFileInfo['lyrics3']['tag_offset_start']) && isset($ThisFileInfo['lyrics3']['tag_offset_end'])) {
if (is_readable($this->filename) && is_writable($this->filename) && is_file($this->filename) && ($fp = fopen($this->filename, 'a+b'))) {
flock($fp, LOCK_EX);
$oldignoreuserabort = ignore_user_abort(true);
fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_end'], SEEK_SET);
$DataAfterLyrics3 = '';
if ($ThisFileInfo['filesize'] > $ThisFileInfo['lyrics3']['tag_offset_end']) {
$DataAfterLyrics3 = fread($fp, $ThisFileInfo['filesize'] - $ThisFileInfo['lyrics3']['tag_offset_end']);
}
ftruncate($fp, $ThisFileInfo['lyrics3']['tag_offset_start']);
if (!empty($DataAfterLyrics3)) {
fseek($fp, $ThisFileInfo['lyrics3']['tag_offset_start'], SEEK_SET);
fwrite($fp, $DataAfterLyrics3, strlen($DataAfterLyrics3));
}
flock($fp, LOCK_UN);
fclose($fp);
ignore_user_abort($oldignoreuserabort);
return true;
} else {
$this->errors[] = 'Cannot fopen(' . $this->filename . ', "a+b")';
return false;
}
}
// no Lyrics3 present
return true;
}
示例2: mkdir
*/
public function mkdir($savepath)
{
return true;
}
/**
* 保存指定文件
* @param array $file 保存的文件信息
* @param boolean $replace 同名文件是否覆盖
* @return boolean 保存状态,true-成功,false-失败
*/
public function save($file, $replace = true)
{
$header['Content-Type'] = $file['type'];
$header['Content-MD5'] = $file['md5'];
$header['Mkdir'] = 'true';
$resource = fopen($file['tmp_name'], 'r');
$save = $this->rootPath . $file['savepath'] . $file['savename'];
$data = $this->request($save, 'PUT', $header, $resource);
return false === $data ? false : true;
}
/**
* 获取最后一次上传错误信息
* @return string 错误信息
*/
public function getError()
{
return $this->error;
}
/**
* 请求又拍云服务器
* @param string $path 请求的PATH
* @param string $method 请求方法
* @param array $headers 请求header
* @param resource $body 上传文件资源
* @return boolean
*/
private function request($path, $method, $headers = null, $body = null)
{
$uri = "/{$this->config['bucket']}/{$path}";
$ch = curl_init($this->config['host'] . $uri);
$_headers = array('Expect:');
if (!is_null($headers) && is_array($headers)) {
foreach ($headers as $k => $v) {
array_push($_headers, "{$k}: {$v}");
}
}
$length = 0;
$date = gmdate('D, d M Y H:i:s \\G\\M\\T');
if (!is_null($body)) {
if (is_resource($body)) {
fseek($body, 0, SEEK_END);
$length = ftell($body);
fseek($body, 0);
array_push($_headers, "Content-Length: {$length}");
curl_setopt($ch, CURLOPT_INFILE, $body);
curl_setopt($ch, CURLOPT_INFILESIZE, $length);
} else {
$length = @strlen($body);
array_push($_headers, "Content-Length: {$length}");
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
示例3: fsize
function fsize($file)
{
// filesize will only return the lower 32 bits of
// the file's size! Make it unsigned.
$fmod = filesize($file);
if ($fmod < 0) {
$fmod += 2.0 * (PHP_INT_MAX + 1);
}
// find the upper 32 bits
$i = 0;
$myfile = fopen($file, "r");
// feof has undefined behaviour for big files.
// after we hit the eof with fseek,
// fread may not be able to detect the eof,
// but it also can't read bytes, so use it as an
// indicator.
while (strlen(fread($myfile, 1)) === 1) {
fseek($myfile, PHP_INT_MAX, SEEK_CUR);
$i++;
}
fclose($myfile);
// $i is a multiplier for PHP_INT_MAX byte blocks.
// return to the last multiple of 4, as filesize has modulo of 4 GB (lower 32 bits)
if ($i % 2 == 1) {
$i--;
}
// add the lower 32 bit to our PHP_INT_MAX multiplier
return (double) $i * (PHP_INT_MAX + 1) + $fmod;
}
示例4: analyze
/**
* @return bool
*/
public function analyze()
{
$info =& $this->getid3->info;
fseek($this->getid3->fp, $info['avdataoffset'], SEEK_SET);
$EXEheader = fread($this->getid3->fp, 28);
$magic = 'MZ';
if (substr($EXEheader, 0, 2) != $magic) {
$info['error'][] = 'Expecting "' . Helper::PrintHexBytes($magic) . '" at offset ' . $info['avdataoffset'] . ', found "' . Helper::PrintHexBytes(substr($EXEheader, 0, 2)) . '"';
return false;
}
$info['fileformat'] = 'exe';
$info['exe']['mz']['magic'] = 'MZ';
$info['exe']['mz']['raw']['last_page_size'] = Helper::LittleEndian2Int(substr($EXEheader, 2, 2));
$info['exe']['mz']['raw']['page_count'] = Helper::LittleEndian2Int(substr($EXEheader, 4, 2));
$info['exe']['mz']['raw']['relocation_count'] = Helper::LittleEndian2Int(substr($EXEheader, 6, 2));
$info['exe']['mz']['raw']['header_paragraphs'] = Helper::LittleEndian2Int(substr($EXEheader, 8, 2));
$info['exe']['mz']['raw']['min_memory_paragraphs'] = Helper::LittleEndian2Int(substr($EXEheader, 10, 2));
$info['exe']['mz']['raw']['max_memory_paragraphs'] = Helper::LittleEndian2Int(substr($EXEheader, 12, 2));
$info['exe']['mz']['raw']['initial_ss'] = Helper::LittleEndian2Int(substr($EXEheader, 14, 2));
$info['exe']['mz']['raw']['initial_sp'] = Helper::LittleEndian2Int(substr($EXEheader, 16, 2));
$info['exe']['mz']['raw']['checksum'] = Helper::LittleEndian2Int(substr($EXEheader, 18, 2));
$info['exe']['mz']['raw']['cs_ip'] = Helper::LittleEndian2Int(substr($EXEheader, 20, 4));
$info['exe']['mz']['raw']['relocation_table_offset'] = Helper::LittleEndian2Int(substr($EXEheader, 24, 2));
$info['exe']['mz']['raw']['overlay_number'] = Helper::LittleEndian2Int(substr($EXEheader, 26, 2));
$info['exe']['mz']['byte_size'] = ($info['exe']['mz']['raw']['page_count'] - 1) * 512 + $info['exe']['mz']['raw']['last_page_size'];
$info['exe']['mz']['header_size'] = $info['exe']['mz']['raw']['header_paragraphs'] * 16;
$info['exe']['mz']['memory_minimum'] = $info['exe']['mz']['raw']['min_memory_paragraphs'] * 16;
$info['exe']['mz']['memory_recommended'] = $info['exe']['mz']['raw']['max_memory_paragraphs'] * 16;
$info['error'][] = 'EXE parsing not enabled in this version of GetId3Core() [' . $this->getid3->version() . ']';
return false;
}
示例5: _fstrpos
function _fstrpos($resource, $str, $direction = 1)
{
$pos = ftell($resource);
$buff = fgets($resource);
fseek($resource, $pos);
return $pos + ($direction == 1 ? strpos($buff, $str) : strrpos($buff, $str));
}
示例6: executeTask
/**
* Executes the task
*
* @param array $uParameters parameters
* @param FormatterInterface $uFormatter formatter class
*
* @return int exit code
*/
public function executeTask(array $uParameters, FormatterInterface $uFormatter)
{
if (!isset($uParameters[0])) {
$uFormatter->writeColor("red", "parameter needed: database name.");
return 1;
}
$tDatabase = $uParameters[0];
// set up server class
$tServer = new Server($this->services);
$tServer->connect();
// set output
$tHandle = tmpfile();
// start dumping database to a local file
$uFormatter->writeColor("green", "reading sql dump from the server for database '{$tDatabase}'...");
$tServer->dump($tDatabase, $tHandle);
// seek to the beginning
fseek($tHandle, 0);
// set up client class
$tClient = new Client($this->services);
$uFormatter->writeColor("green", "writing dump to the client...");
// execute sql at the client
$tClient->connect();
$tClient->dropAndCreateDatabase($tDatabase);
$tClient->executeStream($tHandle);
// close and destroy the file
fclose($tHandle);
$uFormatter->writeColor("yellow", "done.");
return 0;
}
示例7: read_history
function read_history($history_file, $history_pos, $repo_path)
{
$fp = fopen($history_file, "r") or die("Unable to open file!");
$pos = -2;
// Skip final new line character (Set to -1 if not present)
$lines = array();
$currentLine = '';
while (-1 !== fseek($fp, $pos, SEEK_END)) {
$char = fgetc($fp);
if (PHP_EOL == $char) {
$lines[] = $currentLine;
$currentLine = '';
} else {
$currentLine = $char . $currentLine;
}
$pos--;
}
list($result, $build_id, $branch, $commit_id, $ci_pipeline_time) = split('[|]', $lines[$history_pos]);
list($dummy, $result) = split('[:]', $result);
$result = trim($result);
list($dummy, $build_id) = split('[:]', $build_id);
$build_id = trim($build_id);
list($dummy, $branch) = split('[:]', $branch);
$branch = trim($branch);
list($dummy, $commit_id) = split('[:]', $commit_id);
$commit_id = substr(trim($commit_id), -10);
list($dummy, $ci_pipeline_time) = split('[:]', $ci_pipeline_time);
$ci_pipeline_time = substr(trim($ci_pipeline_time), -10);
$history = array("result" => $result, "build_id" => $build_id, "branch" => $branch, "commit_id" => $commit_id, "artifact_path" => "{$repo_path}/ci_fuel_opnfv/artifact/{$branch}/{$build_id}", "log" => "{$repo_path}/ci_fuel_opnfv/artifact/{$branch}/{$build_id}/ci.log", "iso" => "{$repo_path}/ci_fuel_opnfv/artifact/{$branch}/{$build_id}/opnfv-{$build_id}.iso", "ci_pipeline_time" => $ci_pipeline_time);
return $history;
}
示例8: export
public function export(\Contao\DC_Table $dc)
{
$database = \Contao\Database::getInstance();
$stage_id = $database->query("SELECT s.id FROM tl_beachcup_stage AS s WHERE s.start_date >= UNIX_TIMESTAMP() ORDER BY s.start_date ASC LIMIT 1")->fetchAssoc()["id"];
$data = $database->query("select tl_beachcup_registration.id as ANMELDUNG_ID, tl_beachcup_tournament.name_de AS TURNIER, DATE_FORMAT(from_unixtime(tl_beachcup_registration.tstamp), '%d.%m.%Y') as DATUM_ANMELDUNG,\n p1.surname as NACHNAME_1, p1.name as VORNAME_1, p1.tax_number as STEUER_NR_1, DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL p1.birth_date SECOND), '%d.%m.%Y') as GEB_DATUM_1, p1.birth_place as GEB_ORT_1, p1.gender as GESCHLECHT_1, p1.address as ADRESSE_1, p1.zip_code as PLZ_1, p1.city as ORT_1, p1.country as LAND_1, p1.email as EMAIL_1, p1.phone_number as TEL_1, p1.shirt_size as SHIRT_1, p1.has_shirt as SHIRT_ERHALTEN_1, p1.is_fipav as FIPAV_1, p1level.description_de as SPIELER_LEVEL_1, p1.has_medical_certificate as AERZTL_ZEUGNIS_1, p1.is_confirmed as EIGENERKLAERUNG_1,\n p2.surname as NACHNAME_2, p2.name as VORNAME_2, p2.tax_number as STEUER_NR_2, DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL p2.birth_date SECOND), '%d.%m.%Y') as GEB_DATUM_2, p2.birth_place as GEB_ORT_2, p2.gender as GESCHLECHT_2, p2.address as ADRESSE_2, p2.zip_code as PLZ_2, p2.city as ORT_2, p2.country as LAND_2, p2.email as EMAIL_2, p2.phone_number as TEL_2, p2.shirt_size as SHIRT_2, p2.has_shirt as SHIRT_ERHALTEN_2, p2.is_fipav as FIPAV_2, p2level.description_de as SPIELER_LEVEL_2, p2.has_medical_certificate as AERZTL_ZEUGNIS_2, p2.is_confirmed as EIGENERKLAERUNG_2,\n tl_beachcup_registration_state.code as STATUS_ANMELDUNG\n from tl_beachcup_registration\n join tl_beachcup_team on tl_beachcup_team.id = tl_beachcup_registration.team_id\n join tl_beachcup_player p1 on p1.id = tl_beachcup_team.player_1\n join tl_beachcup_player_level p1level on p1level.id = p1.player_level\n join tl_beachcup_player p2 on p2.id = tl_beachcup_team.player_2\n join tl_beachcup_player_level p2level on p2level.id = p2.player_level\n join tl_beachcup_tournament on tl_beachcup_tournament.id = tl_beachcup_registration.tournament_id\n join tl_beachcup_registration_state on tl_beachcup_registration_state.id = tl_beachcup_registration.state_id\n join tl_beachcup_stage on tl_beachcup_stage.id = tl_beachcup_tournament.stage_id\n where tl_beachcup_stage.id = {$stage_id} and tl_beachcup_registration_state.code != 'REJECTED'\n order by tl_beachcup_tournament.date, tl_beachcup_tournament.name_de, tl_beachcup_registration.tstamp;")->fetchAllAssoc();
if (count($data) > 0) {
$headers = array();
foreach ($data[0] as $key => $value) {
$headers[] = $key;
}
$file = fopen("php://memory", "w");
fputcsv($file, $headers, ";");
foreach ($data as $record) {
fputcsv($file, $record, ";");
}
fseek($file, 0);
header('Content-Encoding: iso-8859-1');
header('Content-Type: application/csv; charset=iso-8859-1');
header('Content-Disposition: attachement; filename="Anmeldungen.csv";');
echo "";
fpassthru($file);
exit;
}
\Contao\Controller::redirect('contao/main.php?do=registration');
}
示例9: load
public function load()
{
/**
* Trick: open in append mode to read,
* place pointer to begin
* create if not exists
*/
$f = fopen($this->_configFile, "a+");
fseek($f, 0, SEEK_SET);
$size = filesize($this->_configFile);
if (!$size) {
$this->store();
return;
}
$headerLen = strlen(self::HEADER);
$contents = fread($f, $headerLen);
if (self::HEADER != $contents) {
$this->store();
return;
}
$size -= $headerLen;
$contents = fread($f, $size);
$data = @unserialize($contents);
if ($data === unserialize(false)) {
$this->store();
return;
}
foreach ($data as $k => $v) {
$this->{$k} = $v;
}
fclose($f);
}
示例10: SaveSession
function SaveSession($session)
{
$name = $this->file['name'];
if (!$this->opened_file) {
if (!($this->opened_file = fopen($name, 'c+'))) {
return $this->SetPHPError('could not open the token file ' . $name, $php_error_message);
}
}
if (!flock($this->opened_file, LOCK_EX)) {
return $this->SetPHPError('could not lock the token file ' . $name . ' for writing', $php_error_message);
}
if (fseek($this->opened_file, 0)) {
return $this->SetPHPError('could not rewind the token file ' . $name . ' for writing', $php_error_message);
}
if (!ftruncate($this->opened_file, 0)) {
return $this->SetPHPError('could not truncate the token file ' . $name . ' for writing', $php_error_message);
}
if (!fwrite($this->opened_file, json_encode($session))) {
return $this->SetPHPError('could not write to the token file ' . $name, $php_error_message);
}
if (!fclose($this->opened_file)) {
return $this->SetPHPError('could not close to the token file ' . $name, $php_error_message);
}
$this->opened_file = false;
return true;
}
示例11: seek
/**
* {@inheritdoc}
*
* @see \Contrib\Component\File\SeekableFileInterface::seek()
*/
public function seek($offset, $whence = SEEK_SET)
{
if (isset($this->handle) && is_resource($this->handle)) {
return fseek($this->handle, $offset, $whence) === 0;
}
throw new \RuntimeException('File handle is not set.');
}
示例12: connect
function connect($filename, $encode = "EUC-JP")
{
$allData = array();
//一時ファイルを使い、一気に文字コード変換
if (!file_exists($filename)) {
return false;
}
if (!($fileData = file_get_contents($filename))) {
return false;
}
$fileData = mb_convert_encoding($fileData, "UTF-8", $encode);
// 一時ファイルに書き込み
$handle = tmpfile();
$size = fwrite($handle, $fileData);
fseek($handle, 0);
while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) {
$line = array();
foreach ($data as $val) {
echo $val;
$line[] = trim($val);
}
$allData[] = $line;
}
fclose($handle);
if ($this->allData = $allData) {
return true;
} else {
return false;
}
}
示例13: getid3_exe
function getid3_exe(&$fd, &$ThisFileInfo)
{
fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
$EXEheader = fread($fd, 28);
if (substr($EXEheader, 0, 2) != 'MZ') {
$ThisFileInfo['error'][] = 'Expecting "MZ" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "' . substr($EXEheader, 0, 2) . '" instead.';
return false;
}
$ThisFileInfo['fileformat'] = 'exe';
$ThisFileInfo['exe']['mz']['magic'] = 'MZ';
$ThisFileInfo['exe']['mz']['raw']['last_page_size'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 2, 2));
$ThisFileInfo['exe']['mz']['raw']['page_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 4, 2));
$ThisFileInfo['exe']['mz']['raw']['relocation_count'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 6, 2));
$ThisFileInfo['exe']['mz']['raw']['header_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 8, 2));
$ThisFileInfo['exe']['mz']['raw']['min_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 10, 2));
$ThisFileInfo['exe']['mz']['raw']['max_memory_paragraphs'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 12, 2));
$ThisFileInfo['exe']['mz']['raw']['initial_ss'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 14, 2));
$ThisFileInfo['exe']['mz']['raw']['initial_sp'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 16, 2));
$ThisFileInfo['exe']['mz']['raw']['checksum'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 18, 2));
$ThisFileInfo['exe']['mz']['raw']['cs_ip'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 20, 4));
$ThisFileInfo['exe']['mz']['raw']['relocation_table_offset'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 24, 2));
$ThisFileInfo['exe']['mz']['raw']['overlay_number'] = getid3_lib::LittleEndian2Int(substr($EXEheader, 26, 2));
$ThisFileInfo['exe']['mz']['byte_size'] = ($ThisFileInfo['exe']['mz']['raw']['page_count'] - 1) * 512 + $ThisFileInfo['exe']['mz']['raw']['last_page_size'];
$ThisFileInfo['exe']['mz']['header_size'] = $ThisFileInfo['exe']['mz']['raw']['header_paragraphs'] * 16;
$ThisFileInfo['exe']['mz']['memory_minimum'] = $ThisFileInfo['exe']['mz']['raw']['min_memory_paragraphs'] * 16;
$ThisFileInfo['exe']['mz']['memory_recommended'] = $ThisFileInfo['exe']['mz']['raw']['max_memory_paragraphs'] * 16;
$ThisFileInfo['error'][] = 'EXE parsing not enabled in this version of getID3()';
return false;
}
示例14: logAction
public function logAction()
{
$pageSize = 4096;
$overlapSize = 128;
$dir = APPLICATION_PATH . '/../data/logs/';
$file = $this->_getParam('file', null);
$this->view->page = $this->_getParam('page', 0);
if ($file === null) {
$file = sprintf('%s_application.log', Zend_Date::now()->toString('yyyy.MM.dd'));
}
$fp = fopen($dir . $file, 'r');
fseek($fp, -$pageSize * ($this->view->page + 1) + $overlapSize, SEEK_END);
$this->view->errorLog = fread($fp, $pageSize + $overlapSize * 2);
fclose($fp);
$iterator = new DirectoryIterator($dir);
while ($iterator->valid()) {
if (!$iterator->isDot()) {
if ($iterator->isFile()) {
$files[$iterator->getFilename()] = $iterator->getPathName();
}
}
$iterator->next();
}
$this->view->itemCountPerPage = $pageSize;
$this->view->totalItemCount = filesize($dir . $file);
$this->view->files = $files;
}
示例15: find
public static function find($ip)
{
if (empty($ip) === TRUE) {
return 'N/A';
}
$nip = gethostbyname($ip);
$ipdot = explode('.', $nip);
if ($ipdot[0] < 0 || $ipdot[0] > 255 || count($ipdot) !== 4) {
return 'N/A';
}
if (self::$fp === NULL) {
self::init();
}
$nip2 = pack('N', ip2long($nip));
$tmp_offset = (int) $ipdot[0] * 4;
$start = unpack('Vlen', self::$index[$tmp_offset] . self::$index[$tmp_offset + 1] . self::$index[$tmp_offset + 2] . self::$index[$tmp_offset + 3]);
$index_offset = $index_length = NULL;
$max_comp_len = self::$offset['len'] - 1024 - 4;
for ($start = $start['len'] * 8 + 1024; $start < $max_comp_len; $start += 8) {
if (self::$index[$start] . self::$index[$start + 1] . self::$index[$start + 2] . self::$index[$start + 3] >= $nip2) {
$index_offset = unpack('Vlen', self::$index[$start + 4] . self::$index[$start + 5] . self::$index[$start + 6] . "");
$index_length = unpack('Clen', self::$index[$start + 7]);
break;
}
}
if ($index_offset === NULL) {
return 'N/A';
}
fseek(self::$fp, self::$offset['len'] + $index_offset['len'] - 1024);
$ret_arr = explode("\t", fread(self::$fp, $index_length['len']));
return array('country' => $ret_arr[0], 'province' => $ret_arr[1], 'city' => $ret_arr[2]);
}