本文整理汇总了PHP中fread函数的典型用法代码示例。如果您正苦于以下问题:PHP fread函数的具体用法?PHP fread怎么用?PHP fread使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fread函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:vkaran101,项目名称:sase,代码行数:31,代码来源:Bcrypt.php
示例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;
}
开发者ID:abazad,项目名称:whatsappGUI,代码行数:32,代码来源:mediauploader.php
示例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;
}
开发者ID:spMohanty,项目名称:MateCat,代码行数:28,代码来源:DetectProprietaryXliff.php
示例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);
}
开发者ID:leifuchen0111,项目名称:company,代码行数:31,代码来源:UpgradeController.class.php
示例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;
}
}
}
}
开发者ID:Zanej,项目名称:cms,代码行数:28,代码来源:Rewrite.php
示例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;
}
开发者ID:netor27,项目名称:UnovaPrivado,代码行数:29,代码来源:funcionesParaArchivos.php
示例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;
}
开发者ID:phill104,项目名称:branches,代码行数:29,代码来源:codebase.php
示例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;
}
开发者ID:nextgens,项目名称:mantisbt,代码行数:7,代码来源:mc_file_api.php
示例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;
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:40,代码来源:CryptUtil.php
示例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;
}
}
开发者ID:khanhnnvn,项目名称:ilias_E-learning,代码行数:35,代码来源:class.ilHttpRequest.php
示例11: canReadFromLargeFile
/**
* @test
*/
public function canReadFromLargeFile()
{
$fp = fopen($this->largeFile->url(), 'rb');
$data = fread($fp, 15);
fclose($fp);
$this->assertEquals(str_repeat(' ', 15), $data);
}
开发者ID:kdambekalns,项目名称:vfsStream,代码行数:10,代码来源:vfsStreamWrapperLargeFileTestCase.php
示例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));
}
开发者ID:nandor,项目名称:kit,代码行数:31,代码来源:GroupController.php
示例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;
}
开发者ID:Nattpyre,项目名称:rocketfiles,代码行数:34,代码来源:Exe.php
示例14: echoFileContent
public static function echoFileContent($filename)
{
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
echo $contents;
}
开发者ID:sunniecc,项目名称:web_pakpobox,代码行数:7,代码来源:Utils.php
示例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);
}
开发者ID:nishishailesh,项目名称:myLIS,代码行数:7,代码来源:manage_blob.php
示例16: httpGet
function httpGet($host, $base_fd)
{
global $index;
$fd = stream_socket_client("{$host}", $errno, $errstr, 3, STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT);
$index[$fd] = 0;
$event_fd = event_new();
event_set($event_fd, $fd, EV_WRITE | EV_PERSIST, function ($fd, $events, $arg) use($host) {
global $times, $limit, $index;
if (!$index[$fd]) {
$index[$fd] = 1;
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: {$host}\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fd, $out);
} else {
$str = fread($fd, 4096);
echo $str, PHP_EOL;
if (feof($fd)) {
fclose($fd);
$times++;
echo "done\n";
if ($times == $limit - 1) {
event_base_loopexit($arg[1]);
}
}
}
}, array($event_fd, $base_fd));
event_base_set($event_fd, $base_fd);
event_add($event_fd);
}
开发者ID:CraryPrimitiveMan,项目名称:code-examples,代码行数:30,代码来源:http.php
示例17: getDocuments
public function getDocuments($name)
{
if (!file_exists($this->_getFilePathName($name))) {
return array();
}
$fp = fopen($this->_getFilePathName($name), 'r');
$filesize = filesize($this->_getFilePathName($name));
if ($filesize % MULTIINDEX_DOCUMENTBYTESIZE != 0) {
throw new Exception('Filesize not correct index is corrupt!');
}
$ret = array();
$count = 0;
for ($i = 0; $i < $filesize / MULTIINDEX_DOCUMENTBYTESIZE; $i++) {
$bindata1 = fread($fp, MULTIINDEX_DOCUMENTINTEGERBYTESIZE);
$bindata2 = fread($fp, MULTIINDEX_DOCUMENTINTEGERBYTESIZE);
$bindata3 = fread($fp, MULTIINDEX_DOCUMENTINTEGERBYTESIZE);
$data1 = unpack('i', $bindata1);
$data2 = unpack('i', $bindata2);
$data3 = unpack('i', $bindata3);
$ret[] = array($data1[1], $data2[1], $data3[1]);
$count++;
if ($count == MULTIINDEX_DOCUMENTRETURN) {
break;
}
}
fclose($fp);
return $ret;
}
开发者ID:thegeekajay,项目名称:search-engine,代码行数:28,代码来源:multifolderindex.class.php
示例18: signature_split
public function signature_split($orgfile, $input)
{
$info = unpack('n', fread($input, 2));
$blocksize = $info[1];
$this->info['transferid'] = mt_rand();
$count = 0;
$needed = array();
$cache = $this->getCache();
$prefix = $this->getPrefix();
while (!feof($orgfile)) {
$new_md5 = fread($input, 16);
if (feof($input)) {
break;
}
$data = fread($orgfile, $blocksize);
$org_md5 = md5($data, true);
if ($org_md5 == $new_md5) {
$cache->set($prefix . $count, $data);
} else {
$needed[] = $count;
}
$count++;
}
return array('transferid' => $this->info['transferid'], 'needed' => $needed, 'count' => $count);
}
开发者ID:noci2012,项目名称:owncloud,代码行数:25,代码来源:filechunking.php
示例19: download
public static function download($fullPath)
{
if ($fd = fopen($fullPath, 'r')) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts['extension']);
switch ($ext) {
case 'pdf':
header('Content-type: application/pdf');
// add here more headers for diff. extensions
header('Content-Disposition: attachment; filename="' . $path_parts['basename'] . '"');
// use 'attachment' to force a download
break;
default:
header('Content-type: application/octet-stream');
header('Content-Disposition: filename="' . $path_parts['basename'] . '"');
break;
}
header("Content-length: {$fsize}");
header('Cache-control: private');
//use this to open files directly
while (!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose($fd);
}
开发者ID:speedwork,项目名称:util,代码行数:28,代码来源:Utility.php
示例20: form_save
function form_save()
{
if (isset($_POST["save_component_import"])) {
if (trim($_POST["import_text"] != "")) {
/* textbox input */
$xml_data = $_POST["import_text"];
} elseif ($_FILES["import_file"]["tmp_name"] != "none" && $_FILES["import_file"]["tmp_name"] != "") {
/* file upload */
$fp = fopen($_FILES["import_file"]["tmp_name"], "r");
$xml_data = fread($fp, filesize($_FILES["import_file"]["tmp_name"]));
fclose($fp);
} else {
header("Location: templates_import.php");
exit;
}
if ($_POST["import_rra"] == "1") {
$import_custom_rra_settings = false;
} else {
$import_custom_rra_settings = true;
}
/* obtain debug information if it's set */
$debug_data = import_xml_data($xml_data, $import_custom_rra_settings);
if (sizeof($debug_data) > 0) {
$_SESSION["import_debug_info"] = $debug_data;
}
header("Location: templates_import.php");
}
}
开发者ID:BackupTheBerlios,项目名称:odp-svn,代码行数:28,代码来源:templates_import.php
注:本文中的fread函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论