本文整理汇总了PHP中file_put_contents函数的典型用法代码示例。如果您正苦于以下问题:PHP file_put_contents函数的具体用法?PHP file_put_contents怎么用?PHP file_put_contents使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_put_contents函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: command_dd
function command_dd()
{
$args = func_get_args();
$options = $this->get_options();
$dd = kernel::single('dev_docbuilder_dd');
if (empty($args)) {
$dd->export();
} else {
foreach ($args as $app_id) {
$dd->export_tables($app_id);
}
}
if ($filename = $options['result-file']) {
ob_start();
$dd->output();
$out = ob_get_contents();
ob_end_clean();
if (!is_dir(dirname($filename))) {
throw new Exception('cannot find the ' . dirname($filename) . 'directory');
} elseif (is_dir($filename)) {
throw new Exception('the result-file path is a directory.');
}
file_put_contents($options['result-file'], $out);
echo 'data dictionary doc export success.';
} else {
$dd->output();
}
}
示例2: run
/**
* {@inheritdoc}
*/
public function run()
{
if (is_null($this->dst) || "" === $this->dst) {
return Result::error($this, 'You must specify a destination file with to() method.');
}
if (!$this->checkResources($this->files, 'file')) {
return Result::error($this, 'Source files are missing!');
}
if (file_exists($this->dst) && !is_writable($this->dst)) {
return Result::error($this, 'Destination already exists and cannot be overwritten.');
}
$dump = '';
foreach ($this->files as $path) {
foreach (glob($path) as $file) {
$dump .= file_get_contents($file) . "\n";
}
}
$this->printTaskInfo('Writing {destination}', ['destination' => $this->dst]);
$dst = $this->dst . '.part';
$write_result = file_put_contents($dst, $dump);
if (false === $write_result) {
@unlink($dst);
return Result::error($this, 'File write failed.');
}
// Cannot be cross-volume; should always succeed.
@rename($dst, $this->dst);
return Result::success($this);
}
示例3: ensureConfigFile
/**
* Writes a default configuration file to $path if there is none
* @param string $path
* @param string $type
*/
public static function ensureConfigFile($path, $type)
{
if (!is_file($path)) {
$content = self::getExampleConfiguration($type);
file_put_contents($path, $content);
}
}
示例4: template
/**
* Compiles a template and writes it to a cache file, which is used for inclusion.
*
* @param string $file The full path to the template that will be compiled.
* @param array $options Options for compilation include:
* - `path`: Path where the compiled template should be written.
* - `fallback`: Boolean indicating that if the compilation failed for some
* reason (e.g. `path` is not writable), that the compiled template
* should still be returned and no exception be thrown.
* @return string The compiled template.
*/
public static function template($file, array $options = array())
{
$cachePath = Libraries::get(true, 'resources') . '/tmp/cache/templates';
$defaults = array('path' => $cachePath, 'fallback' => false);
$options += $defaults;
$stats = stat($file);
$oname = basename(dirname($file)) . '_' . basename($file, '.php');
$oname .= '_' . ($stats['ino'] ?: hash('md5', $file));
$template = "template_{$oname}_{$stats['mtime']}_{$stats['size']}.php";
$template = "{$options['path']}/{$template}";
if (file_exists($template)) {
return $template;
}
$compiled = static::compile(file_get_contents($file));
if (is_writable($cachePath) && file_put_contents($template, $compiled) !== false) {
foreach (glob("{$options['path']}/template_{$oname}_*.php", GLOB_NOSORT) as $expired) {
if ($expired !== $template) {
unlink($expired);
}
}
return $template;
}
if ($options['fallback']) {
return $file;
}
throw new TemplateException("Could not write compiled template `{$template}` to cache.");
}
示例5: handleSave
function handleSave($value, $oldValue)
{
global $prefs, $user;
$tikilib = TikiLib::lib('tiki');
$trackerId = $this->getConfiguration('trackerId');
$file_name = $this->getConfiguration('file_name');
$file_size = $this->getConfiguration('file_size');
$file_type = $this->getConfiguration('file_type');
$perms = Perms::get('tracker', $trackerId);
if ($perms->attach_trackers && $file_name) {
if ($prefs['t_use_db'] == 'n') {
$fhash = md5($file_name . $tikilib->now);
if (file_put_contents($prefs['t_use_dir'] . $fhash, $value) === false) {
$smarty = TikiLib::lib('smarty');
$smarty->assign('msg', tra('Cannot write to this file:') . $fhash);
$smarty->display("error.tpl");
die;
}
$value = '';
} else {
$fhash = 0;
}
$trklib = TikiLib::lib('trk');
$value = $trklib->replace_item_attachment($oldValue, $file_name, $file_type, $file_size, $value, '', $user, $fhash, '', '', $trackerId, $this->getItemId(), '', false);
}
return array('value' => $value);
}
示例6: deactivate
function deactivate()
{
file_put_contents($this->config["incron"]["path"] . "/bittorrent.stop", "1");
do {
sleep(1);
} while ($this->isActive());
}
示例7: execute
/**
* Execute this task
*
* @param \TYPO3\Surf\Domain\Model\Node $node
* @param \TYPO3\Surf\Domain\Model\Application $application
* @param \TYPO3\Surf\Domain\Model\Deployment $deployment
* @param array $options Supported options: "scriptBasePath" and "scriptIdentifier"
* @return void
* @throws \TYPO3\Surf\Exception\InvalidConfigurationException
* @throws \TYPO3\Surf\Exception\TaskExecutionException
*/
public function execute(Node $node, Application $application, Deployment $deployment, array $options = array())
{
$workspacePath = $deployment->getWorkspacePath($application);
$scriptBasePath = isset($options['scriptBasePath']) ? $options['scriptBasePath'] : Files::concatenatePaths(array($workspacePath, 'Web'));
if (!isset($options['scriptIdentifier'])) {
// Generate random identifier
$factory = new \RandomLib\Factory();
$generator = $factory->getMediumStrengthGenerator();
$scriptIdentifier = $generator->generateString(32, \RandomLib\Generator::CHAR_ALNUM);
// Store the script identifier as an application option
$application->setOption('TYPO3\\Surf\\Task\\Php\\WebOpcacheResetExecuteTask[scriptIdentifier]', $scriptIdentifier);
} else {
$scriptIdentifier = $options['scriptIdentifier'];
}
$localhost = new Node('localhost');
$localhost->setHostname('localhost');
$commands = array('cd ' . escapeshellarg($scriptBasePath), 'rm -f surf-opcache-reset-*');
$this->shell->executeOrSimulate($commands, $localhost, $deployment);
if (!$deployment->isDryRun()) {
$scriptFilename = $scriptBasePath . '/surf-opcache-reset-' . $scriptIdentifier . '.php';
$result = file_put_contents($scriptFilename, '<?php
if (function_exists("opcache_reset")) {
opcache_reset();
}
@unlink(__FILE__);
echo "success";
');
if ($result === false) {
throw new \TYPO3\Surf\Exception\TaskExecutionException('Could not write file "' . $scriptFilename . '"', 1421932414);
}
}
}
示例8: set
/**
* Sets data
*
* @param string $key
* @param string $var
* @param int $expire
* @return boolean
*/
function set($key, $var, $expire = 0)
{
$key = $this->get_item_key($key);
$sub_path = $this->_get_path($key);
$path = $this->_cache_dir . '/' . $sub_path;
$sub_dir = dirname($sub_path);
$dir = dirname($path);
if (!@is_dir($dir)) {
if (!w3_mkdir_from($dir, W3TC_CACHE_DIR)) {
return false;
}
}
$fp = @fopen($path, 'w');
if (!$fp) {
return false;
}
if ($this->_locking) {
@flock($fp, LOCK_EX);
}
@fputs($fp, $var['content']);
@fclose($fp);
if ($this->_locking) {
@flock($fp, LOCK_UN);
}
// some hostings create files with restrictive permissions
// not allowing apache to read it later
@chmod($path, 0644);
$old_entry_path = $path . '.old';
@unlink($old_entry_path);
if (w3_is_apache() && isset($var['headers']) && isset($var['headers']['Content-Type']) && substr($var['headers']['Content-Type'], 0, 8) == 'text/xml') {
file_put_contents(dirname($path) . '/.htaccess', "<IfModule mod_mime.c>\n" . " RemoveType .html_gzip\n" . " AddType text/xml .html_gzip\n" . " RemoveType .html\n" . " AddType text/xml .html\n" . "</IfModule>");
}
return true;
}
示例9: saveToFile
/**
* 将信息写入XML文件中
* @param string $filename
* @param array $xml
* @param string $root 是否给信息添加根节点
* @return boolean
* @static
*/
function saveToFile($filename, $xml, $root = '')
{
$root && ($xml = array($root => $xml));
$xmlString = ArrayXml::serializeXml($xml);
file_put_contents($filename, $xmlString);
return $result;
}
示例10: write
/**
* Defined by Zend_Config_Writer
*
* @param string $filename
* @param Zend_Config $config
* @throws Zend_Config_Exception When filename was not set
* @throws Zend_Config_Exception When filename is not writable
* @return void
*/
public function write($filename = null, Zend_Config $config = null)
{
if ($filename !== null) {
$this->setFilename($filename);
}
if ($config !== null) {
$this->setConfig($config);
}
if ($this->_filename === null) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('No filename was set');
}
if ($this->_config === null) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('No config was set');
}
$data = $this->_config->toArray();
$sectionName = $this->_config->getSectionName();
if (is_string($sectionName)) {
$data = array($sectionName => $data);
}
$arrayString = "<?php\n" . "return " . var_export($data, true) . ";\n";
$result = @file_put_contents($this->_filename, $arrayString);
if ($result === false) {
require_once 'Zend/Config/Exception.php';
throw new Zend_Config_Exception('Could not write to file "' . $this->_filename . '"');
}
}
示例11: driverSet
public function driverSet(string $keyword, $value, int $time = 0, bool $not_exist = false) : bool
{
$file_path = $this->getFilePath($keyword);
$temp_path = $file_path . ".tmp";
$now = time();
$expiring_time = $time ? $now + $time : 0;
$object = ['value' => $value, 'expiring_time' => $expiring_time];
$data = $this->encode($object);
$to_write = true;
if ($not_exist && @file_exists($file_path)) {
$content = file_get_contents($file_path);
$old = $this->decode($content);
$to_write = false;
if ($this->isExpired($old)) {
$to_write = true;
}
}
$written = false;
if ($to_write) {
try {
$written = @file_put_contents($temp_path, $data, LOCK_EX | LOCK_NB) && @rename($temp_path, $file_path);
} catch (\Exception $e) {
$written = false;
}
}
return $written;
}
示例12: stat_write_static_cache
function stat_write_static_cache($cache_file_path, $config_arr)
{
$content = "<?php\r\n";
$content .= "\$data = " . var_export($config_arr, true) . ";\r\n";
$content .= "?>";
file_put_contents($cache_file_path, $content, LOCK_EX);
}
示例13: query_sbrs_ip_16
function query_sbrs_ip_16($ip, $folder)
{
$end_mark = "No address list shown since no email was detected";
$re_range = '/Showing (\\d+) - (\\d+) out of (\\d+)/';
//Showing 1 - 50 out of 83
$path = '';
$row = 50;
$start = 0;
$total = 0;
//$ip = "9.17.1.1"; //@
$path = "{$folder}/{$ip}_{$start}_{$total}.htm";
$query = build_sbrs_query($ip, $start, $row);
$page = query_page2($query);
if (preg_match($re_range, $page, $matches) > 0) {
$total = $matches[3];
}
echo "total: {$total}\n";
$path = "{$folder}/{$ip}_{$start}_{$total}.htm";
echo "path={$path}\n";
file_put_contents($path, $page);
$start += $row;
while ($start <= $total) {
//sleep(1);
$path = "{$folder}/{$ip}_{$start}_{$total}.htm";
$query = build_sbrs_query($ip, $start, $row);
$page = query_page2($query);
echo "path={$path}\n";
file_put_contents($path, $page);
$start += $row;
}
//sleep(1);
if ($page != '') {
return 'OK';
}
}
示例14: postCheckdb
public function postCheckdb()
{
if (!Session::get('step2')) {
return Redirect::to('install/step2');
}
$dbhost = Input::get('dbhost');
$dbuser = Input::get('dbuser');
$dbpass = Input::get('dbpass');
$dbname = Input::get('dbname');
Session::put(array('dbhost' => $dbhost, 'dbuser' => $dbuser, 'dbpass' => $dbpass, 'dbname' => $dbname));
try {
$dbh = new pdo("mysql:host={$dbhost};dbname={$dbname}", $dbuser, $dbpass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
$sql = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/install/res/dump.sql');
$result = $dbh->exec($sql);
$databaseFile = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/install/res/database.php');
$databaseFile = str_replace(array('{DBHOST}', '{DBNAME}', '{DBUSER}', '{DBPASS}'), array($dbhost, $dbname, $dbuser, $dbpass), $databaseFile);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/apps/frontend/config/database.php', $databaseFile);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/apps/backend/config/database.php', $databaseFile);
Session::put('step3', true);
return Illuminate\Support\Facades\Redirect::to('install/step4');
} catch (PDOException $ex) {
Session::put('step3', false);
return Illuminate\Support\Facades\Redirect::to('install/step3')->with('conerror', 'Date invalide');
}
}
示例15: testLifetime
public function testLifetime()
{
$cache = $this->_getCacheDriver();
// Test save
$cache->save('test_key', 'testing this out', 10);
// Test contains to test that save() worked
$this->assertTrue($cache->contains('test_key'));
// Test fetch
$this->assertEquals('testing this out', $cache->fetch('test_key'));
// access private methods
$getFilename = new \ReflectionMethod($cache, 'getFilename');
$getNamespacedId = new \ReflectionMethod($cache, 'getNamespacedId');
$getFilename->setAccessible(true);
$getNamespacedId->setAccessible(true);
$id = $getNamespacedId->invoke($cache, 'test_key');
$filename = $getFilename->invoke($cache, $id);
$data = '';
$lifetime = 0;
$resource = fopen($filename, "r");
if (false !== ($line = fgets($resource))) {
$lifetime = (int) $line;
}
while (false !== ($line = fgets($resource))) {
$data .= $line;
}
$this->assertNotEquals(0, $lifetime, 'previous lifetime could not be loaded');
// update lifetime
$lifetime = $lifetime - 20;
file_put_contents($filename, $lifetime . PHP_EOL . $data);
// test expired data
$this->assertFalse($cache->contains('test_key'));
$this->assertFalse($cache->fetch('test_key'));
}