本文整理汇总了PHP中getFileContents函数的典型用法代码示例。如果您正苦于以下问题:PHP getFileContents函数的具体用法?PHP getFileContents怎么用?PHP getFileContents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getFileContents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: gzip_compress_file
/**
* Compresses a file (creates a gzipped file)
*
* @param string $srcName the source file
* @param string $dstName the destination file name (the compressed one)
*
* @return bool returns true on success, false else
**/
function gzip_compress_file($srcName, $dstName)
{
$success = false;
$data = getFileContents($srcName);
if ($data != "") {
$success = gzip_writeToFile($dstName, $data);
}
return $success;
}
示例2: importTangram
function importTangram($files, $returnFile = true)
{
global $MATCHED, $DEBUG, $IMPORTED;
$output = "";
if (is_string($files)) {
$files = array($files);
} else {
if (!is_array($files)) {
return $output;
}
}
if ($DEBUG) {
var_dump($files);
}
foreach ($files as $file) {
if (strrpos($file, '*')) {
$output .= importTangram(getPackage(str_replace(array(".", '*'), array('/', ''), $file)));
} elseif (in_array($file, $IMPORTED)) {
continue;
} else {
$IMPORTED[] = $file;
$file = str_replace(".", '/', $file) . ".js";
if ($DEBUG) {
echo "Importing: " . $file . ", returnFile {$returnFile}\n";
}
if (!in_array($file, $MATCHED)) {
$content = getFileContents($file);
if (!$content) {
if ($DEBUG) {
echo "no content... \n;";
}
continue;
}
$MATCHED[] = $file;
$matches = array();
//去掉注释
$content = trim(preg_replace("/\\/\\*(.*?)\\*\\//ies", "", $content)) . "\n";
$output .= preg_replace("/\\/\\/\\/import\\s+([\\w\\-\$]+(\\.[\\w\\-\$]+)*);?/ies", "importTangram('\\1')", $content);
}
}
}
return $output;
}
示例3: getAvailableFiles
function getAvailableFiles($sModule, $sFolder = "langs")
{
global $sIncPath;
global $sModulesUrl;
//--- Get info which was set by admin in the Ray Base ---//
$aFileContents = getFileContents($sModule, "/xml/" . $sFolder . ".xml", true);
$aFiles = $aFileContents['contents'];
//--- Get info from file system ---//
$aRealFiles = getExtraFiles($sModule, $sFolder, false, true);
//--- Merge info from these arrays ---//
$aResult = array();
foreach ($aFiles as $sFile => $bEnabled) {
if ($bEnabled == TRUE_VAL && ($sKey = array_search($sFile, $aRealFiles['files'])) !== false) {
$aResult['files'][] = $sFile;
$aResult['dates'][] = $aRealFiles['dates'][$sKey];
}
}
$aResult['default'] = $aFiles['_default_'];
return $aResult;
}
示例4: deployChangeSet
/**
* Deploys commits to the file-system
*/
function deployChangeSet($postData)
{
global $CONFIG, $DEPLOY, $DEPLOY_BRANCH;
global $processed;
global $rmdirs;
$o = json_decode($postData);
if (!$o) {
// could not parse ?
echo " ! Invalid JSON file\n";
return false;
}
// determine the destination of the deployment
if (array_key_exists($o->repository->slug, $DEPLOY)) {
$deployLocation = $DEPLOY[$o->repository->slug] . (substr($DEPLOY[$o->repository->slug], -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR);
} else {
// unknown repository ?
echo " ! Repository not configured for sync: {$o->repository->slug}\n";
return false;
}
// determine from which branch to get the data
if (isset($DEPLOY_BRANCH) && array_key_exists($o->repository->slug, $DEPLOY_BRANCH)) {
$deployBranch = $DEPLOY_BRANCH[$o->repository->slug];
} else {
// use the default branch
$deployBranch = $CONFIG['deployBranch'];
}
// build URL to get the updated files
$baseUrl = $o->canon_url;
# https://bitbucket.org
$apiUrl = '/api/1.0/repositories';
# /api/1.0/repositories
$repoUrl = $o->repository->absolute_url;
# /user/repo/
$rawUrl = 'raw/';
# raw/
$branchUrl = $deployBranch . '/';
# branch/
// prepare to get the files
$pending = array();
// loop through commits
foreach ($o->commits as $commit) {
// check if the branch is known at this step
loginfo(" > Change-set: " . trim($commit->message) . "\n");
if (!empty($commit->branch) || !empty($commit->branches)) {
// if commit was on the branch we're watching, deploy changes
if ($commit->branch == $deployBranch || !empty($commit->branches) && array_search($deployBranch, $commit->branches) !== false) {
// if there are any pending files, merge them in
$files = array_merge($pending, $commit->files);
// get a list of files
foreach ($files as $file) {
if ($file->type == 'modified' || $file->type == 'added') {
if (empty($processed[$file->file])) {
$processed[$file->file] = 1;
// mark as processed
$contents = getFileContents($baseUrl . $apiUrl . $repoUrl . $rawUrl . $branchUrl . $file->file);
if ($contents == 'Not Found') {
// try one more time, BitBucket gets weirdo sometimes
$contents = getFileContents($baseUrl . $apiUrl . $repoUrl . $rawUrl . $branchUrl . $file->file);
}
if ($contents != 'Not Found' && $contents !== false) {
if (!is_dir(dirname($deployLocation . $file->file))) {
// attempt to create the directory structure first
mkdir(dirname($deployLocation . $file->file), 0755, true);
}
file_put_contents($deployLocation . $file->file, $contents);
loginfo(" - Synchronized {$file->file}\n");
} else {
echo " ! Could not get file contents for {$file->file}\n";
flush();
}
}
} else {
if ($file->type == 'removed') {
unlink($deployLocation . $file->file);
$processed[$file->file] = 0;
// to allow for subsequent re-creating of this file
$rmdirs[dirname($deployLocation . $file->file)] = dirname($file->file);
loginfo(" - Removed {$file->file}\n");
}
}
}
}
// clean pending files, if any
$pending = array();
} else {
// unknown branch for now, keep these files
$pending = array_merge($pending, $commit->files);
}
}
return true;
}
示例5: submit_solution
/**
* This function takes a (set of) temporary file(s) of a submission,
* validates it and puts it into the database. Additionally it
* moves it to a backup storage.
*/
function submit_solution($team, $prob, $contest, $lang, $files, $filenames, $origsubmitid = NULL)
{
global $DB;
if (empty($team)) {
error("No value for Team.");
}
if (empty($prob)) {
error("No value for Problem.");
}
if (empty($contest)) {
error("No value for Contest.");
}
if (empty($lang)) {
error("No value for Language.");
}
if (!is_array($files) || count($files) == 0) {
error("No files specified.");
}
if (count($files) > dbconfig_get('sourcefiles_limit', 100)) {
error("Tried to submit more than the allowed number of source files.");
}
if (!is_array($filenames) || count($filenames) != count($files)) {
error("Nonmatching (number of) filenames specified.");
}
if (count($filenames) != count(array_unique($filenames))) {
error("Duplicate filenames detected.");
}
$sourcesize = dbconfig_get('sourcesize_limit');
// If no contest has started yet, refuse submissions.
$now = now();
$contestdata = $DB->q('MAYBETUPLE SELECT starttime,endtime FROM contest WHERE cid = %i', $contest);
if (!isset($contestdata)) {
error("Contest c{$contest} not found.");
}
if (difftime($contestdata['starttime'], $now) > 0) {
error("The contest is closed, no submissions accepted. [c{$contest}]");
}
// Check 2: valid parameters?
if (!($langid = $DB->q('MAYBEVALUE SELECT langid FROM language
WHERE langid = %s AND allow_submit = 1', $lang))) {
error("Language '{$lang}' not found in database or not submittable.");
}
if (!($teamid = $DB->q('MAYBEVALUE SELECT teamid FROM team
WHERE teamid = %i AND enabled = 1', $team))) {
error("Team '{$team}' not found in database or not enabled.");
}
$probdata = $DB->q('MAYBETUPLE SELECT probid, points FROM problem
INNER JOIN contestproblem USING (probid)
WHERE probid = %s AND cid = %i AND allow_submit = 1', $prob, $contest);
if (empty($probdata)) {
error("Problem p{$prob} not found in database or not submittable [c{$contest}].");
} else {
$points = $probdata['points'];
$probid = $probdata['probid'];
}
// Reindex arrays numerically to allow simultaneously iterating
// over both $files and $filenames.
$files = array_values($files);
$filenames = array_values($filenames);
$totalsize = 0;
for ($i = 0; $i < count($files); $i++) {
if (!is_readable($files[$i])) {
error("File '" . $files[$i] . "' not found (or not readable).");
}
if (!preg_match(FILENAME_REGEX, $filenames[$i])) {
error("Illegal filename '" . $filenames[$i] . "'.");
}
$totalsize += filesize($files[$i]);
}
if ($totalsize > $sourcesize * 1024) {
error("Submission file(s) are larger than {$sourcesize} kB.");
}
logmsg(LOG_INFO, "input verified");
// Insert submission into the database
$id = $DB->q('RETURNID INSERT INTO submission
(cid, teamid, probid, langid, submittime, origsubmitid)
VALUES (%i, %i, %i, %s, %s, %i)', $contest, $teamid, $probid, $langid, $now, $origsubmitid);
for ($rank = 0; $rank < count($files); $rank++) {
$DB->q('INSERT INTO submission_file
(submitid, filename, rank, sourcecode) VALUES (%i, %s, %i, %s)', $id, $filenames[$rank], $rank, getFileContents($files[$rank], false));
}
// Recalculate scoreboard cache for pending submissions
calcScoreRow($contest, $teamid, $probid);
// Log to event table
$DB->q('INSERT INTO event (eventtime, cid, teamid, langid, probid, submitid, description)
VALUES(%s, %i, %i, %s, %i, %i, "problem submitted")', now(), $contest, $teamid, $langid, $probid, $id);
if (is_writable(SUBMITDIR)) {
// Copy the submission to SUBMITDIR for safe-keeping
for ($rank = 0; $rank < count($files); $rank++) {
$fdata = array('cid' => $contest, 'submitid' => $id, 'teamid' => $teamid, 'probid' => $probid, 'langid' => $langid, 'rank' => $rank, 'filename' => $filenames[$rank]);
$tofile = SUBMITDIR . '/' . getSourceFilename($fdata);
if (!@copy($files[$rank], $tofile)) {
warning("Could not copy '" . $files[$rank] . "' to '" . $tofile . "'");
}
}
//.........这里部分代码省略.........
示例6: parseXml
$aContents[] = parseXml($aXmlTemplates['widget'], $sInner, $sVersion, $sTitle, $sAuthor, $sAuthorUrl, $sImageUrl, $sStatus, $sAdminUrl);
$aTitles[] = $sTitle;
array_multisort($aTitles, $aContents);
$sContent = implode("", $aContents);
}
}
$sContents = makeGroup($sContent, "widgets");
break;
/**
* Gets widget code.
*/
/**
* Gets widget code.
*/
case 'getWidgetCode':
$aResult = getFileContents($sWidget, "/xml/main.xml", true);
if ($aResult['status'] == SUCCESS_VAL) {
$aContents = $aResult['contents'];
$sCode = $aContents['code'];
if (empty($sCode)) {
if (secureCheckWidgetName($sWidget)) {
require_once $sModulesPath . $sWidget . "/inc/constants.inc.php";
$sCode = $aInfo['code'];
}
}
$sContents = parseXml($aXmlTemplates['result'], SUCCESS_VAL, $sCode, $aContents['license']);
} else {
$sContents = parseXml($aXmlTemplates['result'], $aResult['value'], FAILED_VAL);
}
break;
/**
示例7: index_site
//.........这里部分代码省略.........
// if relocated, print message and redirect to new URL
printRedirected($url_status['relocate'], $url_status['path'], $cl);
if (strstr($url_status['path'], "//")) {
// if redirected to absolute URL, use this for further usage
$url = $url_status['path'];
} else {
$relo_url = str_replace($url_parts['query'], "", $url);
// url without query
$relo_url = substr($url, 0, strrpos($relo_url, "/") + 1);
// url without file name
if (strpos($url_status['path'], "./") === 0) {
// if redirected relativ to same folder depth
$url_status['path'] = str_replace("./", "", $url_status['path']);
$url = "" . $relo_url . "" . $url_status['path'] . "";
}
if (strpos($url_status['path'], "../") === 0) {
// if redirected relativ and one folder up
$url_status['path'] = str_replace("./", "", $url_status['path']);
$relo_url = substr($url, 0, strpos($url_parts['path']));
// url without file name
$relo_url = substr($url, 0, strrpos($relo_url, "/") + 1);
// url without last folder
$url = "" . $relo_url . "" . $url_status['path'] . "";
}
}
}
// read file
$contents = array();
$file = '';
$file = file_get_contents($url);
if ($file === FALSE) {
// we know another way to get the content
$get_charset = '';
$contents = getFileContents($url, $get_charset);
$file = $contents['file'];
}
// parse header only
preg_match("@<head[^>]*>(.*?)<\\/head>@si", $file, $regs);
$headdata = $regs[1];
// fetch the tag value
preg_match("/<meta +name *=[\"']?Sphider-plus[\"']? *content=[\"'](.*?)[\"']/i", $headdata, $res);
if (isset($res)) {
if ($authent != $res[1]) {
// invalid value in authentication tag
$skip = '1';
printHeader($omit, $url, $command_line);
printStandardReport('Skipped_03', $command_line, $no_log);
}
} else {
// no authentication tag found in header
$skip = '1';
printHeader($omit, $url, $command_line);
printStandardReport('Skipped_02', $command_line, $no_log);
}
} else {
$skip = '1';
printHeader($omit, $url, $command_line);
printStandardReport('statError', $command_line, $no_log);
}
}
if (!$skip) {
if ($site_id != "" && $reindex == 1) {
mysqltest();
$sql_query = "INSERT into " . $mysql_table_prefix . "temp (link, level, id) values ('{$url}', 0, '{$sessid}')";
$db_con->query($sql_query);
if ($debug && $db_con->errno) {
示例8: updateHexImage
function updateHexImage($hColorData, $sFilePath)
{
$sTargetFileLocation = DIR_IMAGES . $sFilePath;
$sFileContent = getFileContents($sFilePath);
if (!$sFileContent) {
return false;
}
// Ursprünglichen Hue-Wert durch Wert der CI-Farbe ersetzen
$sFileContent = str_replace($hColorData['replace']['search'], $hColorData['replace']['replace'], $sFileContent);
// Neue Dateiinhalte in Zielgrafik schreiben
if (!file_put_contents($sTargetFileLocation, $sFileContent)) {
say('Grafik konnte nicht ueberschrieben werden: ' . $sTargetFileLocation);
return false;
}
say("Grafik eingefaerbt: " . $sTargetFileLocation);
return true;
}
示例9: rest_encode_file
/**
* Encode file contents for POST-ing to REST API.
* Returns contents of $file (optionally limited in size, see
* getFileContents) as encoded string.
*/
function rest_encode_file($file, $sizelimit = TRUE)
{
return urlencode(base64_encode(getFileContents($file, $sizelimit)));
}
示例10: getFileContents
$select .= "<option value='{$val}' {$selected}>{$val}</option>";
}
$select .= "</select>";
?>
<h1>Visa annons</h1>
<p>Välj den annons som du vill visa.</p>
<form method="post">
<fieldset>
<p>
<label for="input1">Annonser:</label><br>
<?php
echo $select;
?>
</p>
<p>
<div style="background:#eee; border:1px solid #999;padding:1em; overflow: auto; text-align: center;">
<p><?php
if ($filename) {
echo getFileContents($filename);
}
?>
</p>
</div>
</p>
</fieldset>
</form>
示例11: explode
if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
$encodings = explode(',', strtolower(preg_replace("/\\s+/", "", $_SERVER['HTTP_ACCEPT_ENCODING'])));
}
if ((in_array('gzip', $encodings) || in_array('x-gzip', $encodings) || isset($_SERVER['---------------'])) && function_exists('ob_gzhandler') && !ini_get('zlib.output_compression')) {
$enc = in_array('x-gzip', $encodings) ? "x-gzip" : "gzip";
$supportsGzip = true;
}
// Use cached file disk cache, if possible
if ($supportsGzip && file_exists($cacheFile)) {
header("Content-Encoding: " . $enc);
echo getFileContents($cacheFile);
die;
} else {
// Add custom files
foreach ($custom as $file) {
$content .= getFileContents($file . '.js');
}
// Generate GZIP'd content, if possible
if ($supportsGzip) {
header("Content-Encoding: " . $enc);
$cacheData = gzencode($content, 9, FORCE_GZIP);
// Write gz file
if ($cacheKey != "") {
putFileContents($cacheFile, $cacheData);
}
// Stream to client
echo $cacheData;
} else {
// Stream uncompressed content
echo $content;
}
示例12: getFileContents
$stmt = $mysqli->query('SELECT id FROM user_competition WHERE user_id = ' . $userId . ' AND competition_id = ' . $competitionId);
if ($stmt->num_rows > 0) {
$userEntered = 1;
}
$mysqli->close();
return $userEntered;
}
$competitionId = 1;
$compTag = 'beyondthewharf';
if (isset($_GET['competitionId'])) {
$competitionId = $_GET['competitionId'];
}
if ($competitionId == 2) {
$compTag = 'vividsydney';
}
$wharfs = getFileContents('../json/wharfs.json');
$userEntered = 0;
if (isset($_GET['step']) || isset($instagramData)) {
if (isset($_GET['step'])) {
$step = $_GET['step'];
} else {
$step = 2;
}
} else {
$step = 1;
}
if (isset($instagramData)) {
$instagramUsername = $instagramData->user->username;
$instagramId = $instagramData->user->id;
$userDetails = getUserDetails($instagramId, $DB_SERVER, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE);
if ($userDetails['id'] > 0) {
示例13: initializeFileList
public function initializeFileList()
{
if (!file_exists($GLOBALS['tupac_directory'] . '/tupac_filelist')) {
sendMessage('creatingFileList', array());
$GLOBALS['pacman_file_list'] = new PacmanFilesList();
} else {
if (!$GLOBALS['pacman_file_list']) {
//sendMessage('reusingFileList',array());
$GLOBALS['pacman_file_list'] = unserialize(getFileContents($GLOBALS['tupac_directory'] . '/tupac_filelist'));
if ($GLOBALS['pacman_file_list'] === false) {
unlink($GLOBALS['tupac_directory'] . '/tupac_filelist');
sendMessage('corruptedFileList', array());
$GLOBALS['pacman_file_list'] = new PacmanFilesList();
} else {
$GLOBALS['pacman_file_list']->updateFileList();
}
}
}
}
示例14: index_url
function index_url($url, $level, $site_id, $md5sum, $domain, $indexdate, $sessid, $can_leave_domain, $reindex)
{
global $min_delay;
global $command_line;
global $min_words_per_page;
global $supdomain, $index_vpaths;
global $user_agent, $tmp_urls, $delay_time, $domain_arr;
global $db;
$deletable = 0;
$url_status = url_status($url);
$thislevel = $level - 1;
if (strstr($url_status['state'], "Relocation")) {
$url = preg_replace("/ /", "", url_purify($url_status['path'], $url, $can_leave_domain));
if ($url != '') {
$result = $db->query("SELECT link FROM " . TABLE_PREFIX . "temp WHERE link=" . $db->quote($url) . " AND id=" . $db->quote($sessid));
echo sql_errorstring(__FILE__, __LINE__);
if ($result->fetch()) {
$result->closeCursor();
$db->exec("INSERT INTO " . TABLE_PREFIX . "temp (link, level, id) VALUES (" . $db->quote($url) . ", " . $db->quote($level) . ", " . $db->quote($sessid) . ")");
echo sql_errorstring(__FILE__, __LINE__);
}
}
$url_status['state'] == "redirected";
}
if (!$index_vpaths && $url_status['state'] == 'ok') {
$url_parts = parse_url($url);
$base = basename($url_parts['path']);
if (strstr($base, '.') == false) {
$url_status['state'] = "directory listing or default redirect";
}
}
ini_set("user_agent", $user_agent);
if ($url_status['state'] == 'ok') {
$OKtoIndex = 1;
$file_read_error = 0;
if (time() - $delay_time < $min_delay) {
sleep($min_delay - (time() - $delay_time));
}
$delay_time = time();
if (!fst_lt_snd(phpversion(), "4.3.0")) {
$file = file_get_contents($url);
if ($file === FALSE) {
$file_read_error = 1;
}
} else {
$fl = @fopen($url, "r");
if ($fl) {
while ($buffer = @fgets($fl, 4096)) {
$file .= $buffer;
}
} else {
$file_read_error = 1;
}
fclose($fl);
}
if ($file_read_error) {
$contents = getFileContents($url);
$file = $contents['file'];
}
$pageSize = number_format(strlen($file) / 1024, 2, ".", "");
printPageSizeReport($pageSize);
if ($url_status['content'] != 'text') {
$file = extract_text($file, $url_status['content']);
}
printStandardReport('starting', $command_line);
$newmd5sum = md5($file);
if ($reindex == 0) {
if ($md5sum == $newmd5sum) {
printStandardReport('md5notChanged', $command_line);
$OKtoIndex = 0;
} else {
if (isDuplicateMD5($newmd5sum)) {
$OKtoIndex = 0;
printStandardReport('duplicate', $command_line);
}
}
}
if (($md5sum != $newmd5sum || $reindex == 1) && $OKtoIndex == 1) {
$urlparts = parse_url($url);
$newdomain = $urlparts['host'];
$type = 0;
// remove link to css file
//get all links from file
$data = clean_file($file, $url, $url_status['content']);
if ($data['noindex'] == 1) {
$OKtoIndex = 0;
$deletable = 1;
printStandardReport('metaNoindex', $command_line);
}
$wordarray = unique_array(explode(" ", $data['content']));
if ($data['nofollow'] != 1) {
$links = get_links($file, $url, $can_leave_domain, $data['base']);
$links = distinct_array($links);
$all_links = count($links);
$numoflinks = 0;
//if there are any, add to the temp table, but only if there isnt such url already
if (is_array($links)) {
reset($links);
while ($thislink = each($links)) {
if (!isset($tmp_urls[$thislink[1]]) || $tmp_urls[$thislink[1]] != 1) {
//.........这里部分代码省略.........
示例15: get_url_content
function get_url_content($url)
{
$data = getFileContents($url);
if ($data["state"] == "ok") {
return $data["file"];
} else {
return getfile($url);
}
}