本文整理汇总了PHP中fread函数的典型用法代码示例。如果您正苦于以下问题:PHP fread函数的具体用法?PHP fread怎么用?PHP fread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fread函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRandomBytes
private function getRandomBytes($count)
{
$bytes = '';
if (function_exists('openssl_random_pseudo_bytes') && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
// OpenSSL slow on Win
$bytes = openssl_random_pseudo_bytes($count);
}
if ($bytes === '' && @is_readable('/dev/urandom') && ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) {
$bytes = fread($hRand, $count);
fclose($hRand);
}
if (strlen($bytes) < $count) {
$bytes = '';
if ($this->randomState === null) {
$this->randomState = microtime();
if (function_exists('getmypid')) {
$this->randomState .= getmypid();
}
}
for ($i = 0; $i < $count; $i += 16) {
$this->randomState = md5(microtime() . $this->randomState);
if (PHP_VERSION >= '5') {
$bytes .= md5($this->randomState, true);
} else {
$bytes .= pack('H*', md5($this->randomState));
}
}
$bytes = substr($bytes, 0, $count);
}
return $bytes;
}
示例2: sendData
protected static function sendData($host, $POST, $HEAD, $filepath, $mediafile, $TAIL)
{
$sock = fsockopen("ssl://" . $host, 443);
fwrite($sock, $POST);
fwrite($sock, $HEAD);
//write file data
$buf = 1024;
$totalread = 0;
$fp = fopen($filepath, "r");
while ($totalread < $mediafile['filesize']) {
$buff = fread($fp, $buf);
fwrite($sock, $buff, $buf);
$totalread += $buf;
}
//echo $TAIL;
fwrite($sock, $TAIL);
sleep(1);
$data = fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
$data .= fgets($sock, 8192);
fclose($sock);
list($header, $body) = preg_split("/\\R\\R/", $data, 2);
$json = json_decode($body);
if (!is_null($json)) {
return $json;
}
return false;
}
示例3: isXliff
public static function isXliff($stringData = null, $fullPathToFile = null)
{
self::_reset();
$info = array();
if (!empty($stringData) && empty($fullPathToFile)) {
$stringData = substr($stringData, 0, 1024);
} elseif (empty($stringData) && !empty($fullPathToFile)) {
$info = FilesStorage::pathinfo_fix($fullPathToFile);
$file_pointer = fopen("{$fullPathToFile}", 'r');
// Checking Requirements (By specs, I know that xliff version is in the first 1KB)
$stringData = fread($file_pointer, 1024);
fclose($file_pointer);
} elseif (!empty($stringData) && !empty($fullPathToFile)) {
//we want to check extension and content
$info = FilesStorage::pathinfo_fix($fullPathToFile);
}
self::$fileType['info'] = $info;
//we want to check extension also if file path is specified
if (!empty($info) && !self::isXliffExtension()) {
//THIS IS NOT an xliff
return false;
}
// preg_match( '|<xliff\s.*?version\s?=\s?["\'](.*?)["\'](.*?)>|si', $stringData, $tmp );
if (!empty($stringData)) {
return array($stringData);
}
return false;
}
示例4: downFile
protected function downFile($path, $file_name)
{
header("Content-type:text/html;charset=utf-8");
// echo $path,$file_name;
//中文兼容
$file_name = iconv("utf-8", "gb2312", $file_name);
//获取网站根目录,这里可以换成你的下载目录
$file_sub_path = $path;
$file_path = $file_sub_path . $file_name;
//判断文件是否存在
if (!file_exists($file_path)) {
echo '文件不存在';
return;
}
$fp = fopen($file_path, "r");
$file_size = filesize($file_path);
//下载文件所需的header申明
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length:" . $file_size);
Header("Content-Disposition: attachment; filename=" . $file_name);
$buffer = 1024;
$file_count = 0;
//返回数据到浏览器
while (!feof($fp) && $file_count < $file_size) {
$file_con = fread($fp, $buffer);
$file_count += $buffer;
echo $file_con;
}
fclose($fp);
}
示例5: readRoutes
public static function readRoutes($url, $params = array())
{
if (isset(self::$routes)) {
} else {
$filename = $_SERVER["DOCUMENT_ROOT"] . "/Init/routing.prop";
$f = fopen($filename, "r");
$r = fread($f, filesize($filename));
$prop = explode("\n", $r);
#print_r($prop);
for ($i = 0; $i < count($prop); $i++) {
if (substr($prop[$i], 0, 4) != " ") {
continue;
}
$params = array();
$row = true;
while ($row) {
$row = self::readRoutingRow($prop[$i++]);
if ($row) {
$params[$row[0]] = $row[1];
}
}
$i--;
if (self::checkMe($url, $params)) {
break;
}
}
}
}
示例6: 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;
}
示例7: final_extract_install
function final_extract_install()
{
global $CONFIG, $lang_plugin_final_extract, $lang_plugin_final_extract_config, $thisplugin;
require 'plugins/final_extract/configuration.php';
require 'include/sql_parse.php';
if (!isset($CONFIG['fex_enable'])) {
$query = "INSERT INTO " . $CONFIG['TABLE_CONFIG'] . " VALUES ('fex_enable', '1');";
cpg_db_query($query);
// create table
$db_schema = $thisplugin->fullpath . '/schema.sql';
$sql_query = fread(fopen($db_schema, 'r'), filesize($db_schema));
$sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query);
$sql_query = remove_remarks($sql_query);
$sql_query = split_sql_file($sql_query, ';');
foreach ($sql_query as $q) {
cpg_db_query($q);
}
// Put default setting
$db_schema = $thisplugin->fullpath . '/basic.sql';
$sql_query = fread(fopen($db_schema, 'r'), filesize($db_schema));
$sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query);
$sql_query = remove_remarks($sql_query);
$sql_query = split_sql_file($sql_query, ';');
foreach ($sql_query as $q) {
cpg_db_query($q);
}
}
return true;
}
示例8: mci_file_read_local
function mci_file_read_local($p_diskfile)
{
$t_handle = fopen($p_diskfile, "r");
$t_content = fread($t_handle, filesize($p_diskfile));
fclose($t_handle);
return $t_content;
}
示例9: getBytes
/**
* Get the specified number of random bytes.
*
* Attempts to use a cryptographically secure (not predictable)
* source of randomness if available. If there is no high-entropy
* randomness source available, it will fail. As a last resort,
* for non-critical systems, define
* <code>Auth_OpenID_RAND_SOURCE</code> as <code>null</code>, and
* the code will fall back on a pseudo-random number generator.
*
* @param int $num_bytes The length of the return value
* @return string $bytes random bytes
*/
function getBytes($num_bytes)
{
static $f = null;
$bytes = '';
if ($f === null) {
if (Auth_OpenID_RAND_SOURCE === null) {
$f = false;
} else {
$f = @fopen(Auth_OpenID_RAND_SOURCE, "r");
if ($f === false) {
$msg = 'Define Auth_OpenID_RAND_SOURCE as null to ' . ' continue with an insecure random number generator.';
trigger_error($msg, E_USER_ERROR);
}
}
}
if ($f === false) {
// pseudorandom used
$bytes = '';
for ($i = 0; $i < $num_bytes; $i += 4) {
$bytes .= pack('L', mt_rand());
}
$bytes = substr($bytes, 0, $num_bytes);
} else {
$bytes = fread($f, $num_bytes);
}
return $bytes;
}
示例10: downloadToString
function downloadToString()
{
$crlf = "\r\n";
// generate request
$req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf . 'Host: ' . $this->_host . $crlf . $crlf;
// fetch
$this->_fp = fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
fwrite($this->_fp, $req);
while (is_resource($this->_fp) && $this->_fp && !feof($this->_fp)) {
$response .= fread($this->_fp, 1024);
}
fclose($this->_fp);
// split header and body
$pos = strpos($response, $crlf . $crlf);
if ($pos === false) {
return $response;
}
$header = substr($response, 0, $pos);
$body = substr($response, $pos + 2 * strlen($crlf));
// parse headers
$headers = array();
$lines = explode($crlf, $header);
foreach ($lines as $line) {
if (($pos = strpos($line, ':')) !== false) {
$headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos + 1));
}
}
// redirection?
if (isset($headers['location'])) {
$http = new ilHttpRequest($headers['location']);
return $http->DownloadToString($http);
} else {
return $body;
}
}
示例11: canReadFromLargeFile
/**
* @test
*/
public function canReadFromLargeFile()
{
$fp = fopen($this->largeFile->url(), 'rb');
$data = fread($fp, 15);
fclose($fp);
$this->assertEquals(str_repeat(' ', 15), $data);
}
示例12: save_picture
/**
Upload a profile picture for the group
*/
function save_picture($ext)
{
global $cfg;
if (!$this->user->logged_in() || !$this->user->group) {
throw new Exception("Access denied!");
}
if (!isset($_SERVER["CONTENT_LENGTH"])) {
throw new Exception("Invalid parameters");
}
$size = (int) $_SERVER["CONTENT_LENGTH"];
$file_name = rand() . time() . "{$this->user->id}.{$ext}";
$file_path = "{$cfg['dir']['content']}{$file_name}";
// Write the new one
$input = fopen("php://input", "rb");
$output = fopen($file_path, "wb");
if (!$input || !$output) {
throw new Exception("Cannot open files!");
}
while ($size > 0) {
$data = fread($input, $size > 1024 ? 1024 : $size);
$size -= 1024;
fwrite($output, $data);
}
fclose($input);
fclose($output);
// Update the profile image
$this->group->update($this->user->group, array('picture' => $file_name));
}
示例13: 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;
}
示例14: echoFileContent
public static function echoFileContent($filename)
{
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
echo $contents;
}
示例15: file_to_str
function file_to_str($file, $size)
{
$link = start_nchsls();
$fd = fopen($file, 'r');
$str = fread($fd, $size);
return mysql_real_escape_string($str, $link);
}