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
0
파일: Upyun.class.php 프로젝트: RqHe/aunet1
  */
 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);
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
0
 /**
  * @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
0
파일: common.php 프로젝트: neel/bong
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
0
 /**
  * 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
0
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
0
 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
0
 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
0
 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
0
 /**
  * {@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
0
 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
0
 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
0
 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
0
 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]);
 }
예제 #16
0
 /** @todo docblock */
 private function _goto($id)
 {
     fseek($this->_fh, $id == 0 ? 0 : $this->_positions[$id - 1]);
     fgets($this->_fh);
     // consume first line (mbox marker)
     return $this->_positions[$id];
 }
예제 #17
0
파일: file.php 프로젝트: xamiro-dev/xamiro
 /**
  * Read the contents of a file
  *
  * @param string $filename The full file path
  * @param boolean $incpath Use include path
  * @param int $amount Amount of file to read
  * @param int $chunksize Size of chunks to read
  * @param int $offset Offset of the file
  * @return mixed Returns file contents or boolean False if failed
  * @since 1.5
  */
 function read($filename, $incpath = false, $amount = 0, $chunksize = 8192, $offset = 0)
 {
     // Initialize variables
     $data = null;
     if ($amount && $chunksize > $amount) {
         $chunksize = $amount;
     }
     if (false === ($fh = fopen($filename, 'rb', $incpath))) {
         JError::raiseWarning(21, 'extFile::read: ' . JText::_('Unable to open file') . ": '{$filename}'");
         return false;
     }
     clearstatcache();
     if ($offset) {
         fseek($fh, $offset);
     }
     if ($fsize = @filesize($filename)) {
         if ($amount && $fsize > $amount) {
             $data = fread($fh, $amount);
         } else {
             $data = fread($fh, $fsize);
         }
     } else {
         $data = '';
         $x = 0;
         // While its:
         // 1: Not the end of the file AND
         // 2a: No Max Amount set OR
         // 2b: The length of the data is less than the max amount we want
         while (!feof($fh) && (!$amount || strlen($data) < $amount)) {
             $data .= fread($fh, $chunksize);
         }
     }
     fclose($fh);
     return $data;
 }
예제 #18
0
function phpfiwa_check($engine_properties)
{
    $dir = $engine_properties['dir'];
    $files = scandir($dir);
    $feeds = array();
    for ($i = 2; $i < count($files); $i++) {
        $filename_parts = explode(".", $files[$i]);
        $feedid = (int) $filename_parts[0];
        if ($feedid > 0 && !in_array($feedid, $feeds)) {
            $feeds[] = $feedid;
        }
    }
    $error_count = 0;
    $n = 0;
    foreach ($feeds as $id) {
        $error = false;
        $errormsg = "";
        // 1) Analyse meta file
        $feedname = "{$id}.meta";
        // CHECK 1: META FILE EXISTS
        if (!file_exists($dir . $feedname)) {
            print "[Meta file does not exist: {$id}]\n";
            $error = true;
        } else {
            $meta = new stdClass();
            $metafile = fopen($dir . $feedname, 'rb');
            fseek($metafile, 4);
            $tmp = unpack("I", fread($metafile, 4));
            $meta->start_time = $tmp[1];
            $tmp = unpack("I", fread($metafile, 4));
            $meta->nlayers = $tmp[1];
            for ($i = 0; $i < $meta->nlayers; $i++) {
                $tmp = unpack("I", fread($metafile, 4));
            }
            $meta->interval = array();
            for ($i = 0; $i < $meta->nlayers; $i++) {
                $tmp = unpack("I", fread($metafile, 4));
                $meta->interval[$i] = $tmp[1];
            }
            fclose($metafile);
            if ($meta->nlayers < 1 || $meta->nlayers > 4) {
                $errormsg .= "[nlayers out of range: " . $meta->nlayers . "]";
                $error = true;
            }
            if ($meta->start_time > 0 && filesize($dir . $id . "_0.dat") == 0) {
                $errormsg .= "[Start time set but datafile is empty]";
                $error = true;
            }
            if ($error) {
                print "Feed {$id} " . $errormsg . " [" . date("d:m:Y G:i", filemtime($dir . $feedname)) . "]\n";
            }
        }
        if ($error) {
            $error_count++;
        }
        $n++;
    }
    print "Error count: " . $error_count . "\n";
    print "Number of feeds: {$n}\n";
}
예제 #19
0
파일: requesttest.php 프로젝트: 0x17de/core
 protected function getStream($string)
 {
     $stream = fopen('php://temp', 'r+');
     fwrite($stream, $string);
     fseek($stream, 0);
     return $stream;
 }
예제 #20
0
 public function download($file, $name = '', $size = 0, $reload = false)
 {
     if ($name == '') {
         $name = basename($file);
     }
     $fp = fopen($file, 'rb');
     if (!$size) {
         $size = filesize($file);
     }
     $ranges = $this->getRange($size);
     if ($reload && $ranges != null) {
         header('HTTP/1.1 206 Partial Content');
         header('Accept-Ranges:bytes');
         header(sprintf('content-length:%u', $ranges['end'] - $ranges['start']));
         header(sprintf('content-range:bytes %s-%s/%s', $ranges['start'], $ranges['end'], $size));
         fseek($fp, sprintf('%u', $ranges['start']));
     } else {
         header('HTTP/1.1 200 OK');
         header('content-length:' . $size);
     }
     while (!feof($fp)) {
         echo fread($fp, round($this->_speed * 1024, 0));
         ob_flush();
         flush();
         //sleep(1);
     }
     $fp != null && fclose($fp);
 }
예제 #21
0
 function tail($name, $time = null)
 {
     $actions = array();
     $fname = $this->path . '/' . $name . '.php';
     $handle = @fopen($fname, 'r');
     if ($handle) {
         if (!$time) {
             $time = time() - 3600;
         }
         $seekto = 0;
         $fsize = filesize($fname);
         $step = 512;
         while ($fsize + $seekto - $step > 0) {
             fseek($handle, $seekto - $step, SEEK_END);
             fgets($handle);
             $buffer = fgets($handle);
             preg_match('#\\[([0-9]{10})\\]#', $buffer, $marches);
             if ($marches[1] < $time) {
                 break;
             }
             $seekto -= $step;
         }
         while (!feof($handle)) {
             $buffer = fgets($handle, 4096);
             preg_match('#\\[([0-9]{10})\\]\\t#', $buffer, $marches);
             if ($marches[1] >= $time) {
                 $actions[] = $buffer;
             }
         }
         fclose($handle);
         return $actions;
     } else {
         return false;
     }
 }
예제 #22
0
 function getid3_dss(&$fd, &$ThisFileInfo)
 {
     fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
     $DSSheader = fread($fd, 1256);
     if (substr($DSSheader, 0, 4) != "" . 'dss') {
         $ThisFileInfo['error'][] = 'Expecting "[x02]dss" at offset ' . $ThisFileInfo['avdataoffset'] . ', found "' . substr($DSSheader, 0, 4) . '"';
         return false;
     }
     // some structure information taken from http://cpansearch.perl.org/src/RGIBSON/Audio-DSS-0.02/lib/Audio/DSS.pm
     // shortcut
     $ThisFileInfo['dss'] = array();
     $thisfile_dss =& $ThisFileInfo['dss'];
     $ThisFileInfo['fileformat'] = 'dss';
     $ThisFileInfo['audio']['dataformat'] = 'dss';
     $ThisFileInfo['audio']['bitrate_mode'] = 'cbr';
     //$thisfile_dss['encoding']              = 'ISO-8859-1';
     $thisfile_dss['date_create'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 38, 12));
     $thisfile_dss['date_complete'] = $this->DSSdateStringToUnixDate(substr($DSSheader, 50, 12));
     $thisfile_dss['length'] = intval(substr($DSSheader, 62, 6));
     $thisfile_dss['priority'] = ord(substr($DSSheader, 793, 1));
     $thisfile_dss['comments'] = trim(substr($DSSheader, 798, 100));
     //$ThisFileInfo['audio']['bits_per_sample']  = ?;
     //$ThisFileInfo['audio']['sample_rate']      = ?;
     $ThisFileInfo['audio']['channels'] = 1;
     $ThisFileInfo['playtime_seconds'] = $thisfile_dss['length'];
     $ThisFileInfo['audio']['bitrate'] = $ThisFileInfo['filesize'] * 8 / $ThisFileInfo['playtime_seconds'];
     return true;
 }
예제 #23
0
function getGIFHeaderFilepointer(&$fd, &$ThisFileInfo)
{
    $ThisFileInfo['fileformat'] = 'gif';
    $ThisFileInfo['video']['dataformat'] = 'gif';
    $ThisFileInfo['video']['lossless'] = true;
    fseek($fd, $ThisFileInfo['avdataoffset'], SEEK_SET);
    $GIFheader = fread($fd, 13);
    $offset = 0;
    $ThisFileInfo['gif']['header']['raw']['identifier'] = substr($GIFheader, $offset, 3);
    $offset += 3;
    $ThisFileInfo['gif']['header']['raw']['version'] = substr($GIFheader, $offset, 3);
    $offset += 3;
    $ThisFileInfo['gif']['header']['raw']['width'] = LittleEndian2Int(substr($GIFheader, $offset, 2));
    $offset += 2;
    $ThisFileInfo['gif']['header']['raw']['height'] = LittleEndian2Int(substr($GIFheader, $offset, 2));
    $offset += 2;
    $ThisFileInfo['gif']['header']['raw']['flags'] = LittleEndian2Int(substr($GIFheader, $offset, 1));
    $offset += 1;
    $ThisFileInfo['gif']['header']['raw']['bg_color_index'] = LittleEndian2Int(substr($GIFheader, $offset, 1));
    $offset += 1;
    $ThisFileInfo['gif']['header']['raw']['aspect_ratio'] = LittleEndian2Int(substr($GIFheader, $offset, 1));
    $offset += 1;
    $ThisFileInfo['video']['resolution_x'] = $ThisFileInfo['gif']['header']['raw']['width'];
    $ThisFileInfo['video']['resolution_y'] = $ThisFileInfo['gif']['header']['raw']['height'];
    $ThisFileInfo['gif']['version'] = $ThisFileInfo['gif']['header']['raw']['version'];
    $ThisFileInfo['gif']['header']['flags']['global_color_table'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80);
    if ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x80) {
        // Number of bits per primary color available to the original image, minus 1
        $ThisFileInfo['gif']['header']['bits_per_pixel'] = 3 * ((($ThisFileInfo['gif']['header']['raw']['flags'] & 0x70) >> 4) + 1);
    } else {
        $ThisFileInfo['gif']['header']['bits_per_pixel'] = 0;
    }
    $ThisFileInfo['gif']['header']['flags']['global_color_sorted'] = (bool) ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x40);
    if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) {
        // the number of bytes contained in the Global Color Table. To determine that
        // actual size of the color table, raise 2 to [the value of the field + 1]
        $ThisFileInfo['gif']['header']['global_color_size'] = pow(2, ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x7) + 1);
        $ThisFileInfo['video']['bits_per_sample'] = ($ThisFileInfo['gif']['header']['raw']['flags'] & 0x7) + 1;
    } else {
        $ThisFileInfo['gif']['header']['global_color_size'] = 0;
    }
    if ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] != 0) {
        // Aspect Ratio = (Pixel Aspect Ratio + 15) / 64
        $ThisFileInfo['gif']['header']['aspect_ratio'] = ($ThisFileInfo['gif']['header']['raw']['aspect_ratio'] + 15) / 64;
    }
    if ($ThisFileInfo['gif']['header']['flags']['global_color_table']) {
        $GIFcolorTable = fread($fd, 3 * $ThisFileInfo['gif']['header']['global_color_size']);
        $offset = 0;
        for ($i = 0; $i < $ThisFileInfo['gif']['header']['global_color_size']; $i++) {
            //$ThisFileInfo['gif']['global_color_table']['red'][$i]   = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            //$ThisFileInfo['gif']['global_color_table']['green'][$i] = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            //$ThisFileInfo['gif']['global_color_table']['blue'][$i]  = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            $red = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            $green = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            $blue = LittleEndian2Int(substr($GIFcolorTable, $offset++, 1));
            $ThisFileInfo['gif']['global_color_table'][$i] = $red << 16 | $green << 8 | $blue;
        }
    }
    return true;
}
예제 #24
0
function put_ntriples($ntriples, $graphname)
{
    /** use a max of 256KB of RAM before going to disk */
    $fp = fopen('php://temp/maxmemory:256000', 'w');
    if (!$fp) {
        throw new Exception('Could not open temp memory data! PUT failed.');
    }
    fwrite($fp, $ntriples);
    fseek($fp, 0);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, ENDPOINT . '?graph=' . urlencode($graphname));
    curl_setopt($ch, CURLOPT_PUT, 1);
    //	curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain; charset=utf-8'));
    curl_setopt($ch, CURLOPT_INFILE, $fp);
    // file pointer
    curl_setopt($ch, CURLOPT_INFILESIZE, strlen($ntriples));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $out = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if (strpos($httpCode, '2') !== 0) {
        throw new Exception("Cannot PUT dataset. HTTP " . $httpCode . ' ' . $out . "\n" . "=====\n{$body}\n=====");
    }
}
예제 #25
0
function realFilesize($filename)
{
    $fp = fopen($filename, 'r');
    $return = false;
    if (is_resource($fp)) {
        if (PHP_INT_SIZE < 8) {
            if (0 === fseek($fp, 0, SEEK_END)) {
                $return = 0.0;
                $step = 0x7fffffff;
                while ($step > 0) {
                    if (0 === fseek($fp, -$step, SEEK_CUR)) {
                        $return += floatval($step);
                    } else {
                        $step >>= 1;
                    }
                }
            }
        } else {
            if (0 === fseek($fp, 0, SEEK_END)) {
                $return = ftell($fp);
            }
        }
    }
    return $return;
}
    function testLogger()
    {
        $mem = fopen('php://memory', 'rb+');
        $e = array('type' => E_USER_ERROR, 'message' => 'Fake user error', 'file' => 'fake', 'line' => 1, 'scope' => new \Patchwork\PHP\recoverableErrorException(), 'trace' => array(array('function' => 'fake-func2'), array('function' => 'fake-func1')));
        $l = new Logger($mem, 1);
        $l->loggedGlobals = array();
        $l->logError($e, 1, 0, 2);
        fseek($mem, 0);
        $l = stream_get_contents($mem);
        fclose($mem);
        $this->assertStringMatchesFormat('*** php-error ***
{"_":"1:array:3",
  "time": "1970-01-01T01:00:02+01:00 000000us - 1000.000ms - 1000.000ms",
  "mem": "%d - %d",
  "data": {"_":"4:array:4",
    "mesg": "Fake user error",
    "type": "E_USER_ERROR fake:1",
    "scope": {"_":"7:Patchwork\\\\PHP\\\\RecoverableErrorException",
      "*:message": "",
      "*:code": 0,
      "*:file": "' . __FILE__ . '",
      "*:line": 18,
      "*:severity": "E_ERROR"
    },
    "trace": {"_":"13:array:1",
      "0": {"_":"14:array:1",
        "call": "fake-func1()"
      }
    }
  }
}
***
', $l);
    }
 public static function seekPKHeader($handle)
 {
     $pkHeader = false;
     $curr = fgetc($handle);
     do {
         $prev = $curr;
         $curr = fgetc($handle);
         $pk = $prev == "P" && $curr == "K";
         if ($pk) {
             $b1 = fgetc($handle);
             $b2 = fgetc($handle);
             if ($b1 == "" && $b2 == "") {
                 $pkHeader = self::ZIP_CENTRAL_FILE_HEADER;
             } else {
                 if ($b1 == "" && $b2 == "") {
                     $pkHeader = self::ZIP_LOCAL_FILE_HEADER;
                 } else {
                     if ($b1 == "" && $b2 == "") {
                         $pkHeader = self::ZIP_END_OF_CENTRAL_DIRECTORY;
                     } else {
                         if ($b1 == "" && $b2 == "") {
                             $pkHeader = self::ZIP_LOCAL_DATA_DESCRIPTOR;
                         } else {
                             fseek($handle, -2, SEEK_CUR);
                             $pk = false;
                         }
                     }
                 }
             }
         }
     } while (!$pk && !feof($handle));
     fseek($handle, -4, SEEK_CUR);
     return $pkHeader;
 }
예제 #28
0
function convertip_tiny($ip, $ipdatafile)
{
    static $fp = NULL, $offset = array(), $index = NULL;
    $ipdot = explode('.', $ip);
    $ip = pack('N', ip2long($ip));
    $ipdot[0] = (int) $ipdot[0];
    $ipdot[1] = (int) $ipdot[1];
    if ($fp === NULL && ($fp = @fopen($ipdatafile, 'rb'))) {
        $offset = @unpack('Nlen', @fread($fp, 4));
        $index = @fread($fp, $offset['len'] - 4);
    } elseif ($fp == FALSE) {
        return '- IP数据库文件不可用';
    }
    $length = $offset['len'] - 1028;
    $start = @unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);
    for ($start = $start['len'] * 8 + 1024; $start < $length; $start += 8) {
        if ($index[$start] . $index[$start + 1] . $index[$start + 2] . $index[$start + 3] >= $ip) {
            $index_offset = @unpack('Vlen', $index[$start + 4] . $index[$start + 5] . $index[$start + 6] . "");
            $index_length = @unpack('Clen', $index[$start + 7]);
            break;
        }
    }
    @fseek($fp, $offset['len'] + $index_offset['len'] - 1024);
    if ($index_length['len']) {
        return '- ' . @fread($fp, $index_length['len']);
    } else {
        return '- 未知';
    }
}
예제 #29
0
 public static function createTempFile($data)
 {
     $tmpFile = tmpfile();
     fwrite($tmpFile, base64_decode($data));
     fseek($tmpFile, 0);
     return $tmpFile;
 }
예제 #30
0
function write_ini()
{
    unlink(CONFIG);
    $config = new Config_Lite(CONFIG);
    foreach ($_POST as $parameter => $value) {
        $splitParameter = explode('-', $parameter);
        if ($value == "on") {
            $value = "true";
        }
        $config->set($splitParameter[0], $splitParameter[1], $value);
    }
    // save object to file
    try {
        $config->save();
    } catch (Config_Lite_Exception $e) {
        echo "\n" . 'Exception Message: ' . $e->getMessage();
    }
    $cache_new = "; <?php die(\"Access denied\"); ?>";
    // Adds this to the top of the config so that PHP kills the execution if someone tries to request the config-file remotely.
    $file = CONFIG;
    // the file to which $cache_new gets prepended
    $handle = fopen($file, "r+");
    $len = strlen($cache_new);
    $final_len = filesize($file) + $len;
    $cache_old = fread($handle, $len);
    rewind($handle);
    $i = 1;
    while (ftell($handle) < $final_len) {
        fwrite($handle, $cache_new);
        $cache_new = $cache_old;
        $cache_old = fread($handle, $len);
        fseek($handle, $i * $len);
        $i++;
    }
}