本文整理汇总了PHP中file_put_contents函数的典型用法代码示例。如果您正苦于以下问题:PHP file_put_contents函数的具体用法?PHP file_put_contents怎么用?PHP file_put_contents使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了file_put_contents函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
}
}
开发者ID:sss201413,项目名称:ecstore,代码行数:28,代码来源:doc.php
示例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);
}
开发者ID:greg-1-anderson,项目名称:Robo,代码行数:31,代码来源:Concat.php
示例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);
}
}
开发者ID:dlds,项目名称:yii2-payment,代码行数:12,代码来源:InstallHelper.php
示例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.");
}
开发者ID:fedeisas,项目名称:lithium,代码行数:38,代码来源:Compiler.php
示例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);
}
开发者ID:railfuture,项目名称:tiki-website,代码行数:27,代码来源:File.php
示例6: deactivate
function deactivate()
{
file_put_contents($this->config["incron"]["path"] . "/bittorrent.stop", "1");
do {
sleep(1);
} while ($this->isActive());
}
开发者ID:ArmagNet,项目名称:parpaing,代码行数:7,代码来源:BittorrentBo.debian.php
示例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);
}
}
}
开发者ID:TYPO3,项目名称:Surf,代码行数:43,代码来源:WebOpcacheResetCreateScriptTask.php
示例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;
}
开发者ID:marqui678,项目名称:finalchance.Panopta,代码行数:42,代码来源:Generic.php
示例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;
}
开发者ID:a4m,项目名称:go1den-express,代码行数:15,代码来源:ArrayXml.class.php
示例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 . '"');
}
}
开发者ID:gauravstomar,项目名称:Pepool,代码行数:37,代码来源:Array.php
示例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;
}
开发者ID:xiaoliwang,项目名称:phpCache,代码行数:27,代码来源:filesDriver.php
示例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);
}
开发者ID:dalinhuang,项目名称:yy,代码行数:7,代码来源:stat_category.php
示例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';
}
}
开发者ID:ancrux,项目名称:cpp-ex,代码行数:35,代码来源:get_sbrs2.php
示例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');
}
}
开发者ID:vcorobceanu,项目名称:WebAPL,代码行数:25,代码来源:InstallController.php
示例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'));
}
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:33,代码来源:FilesystemCacheTest.php
示例16: wait
public function wait()
{
$data['current'] = array('data_back' => '', 'user_manage' => '', 'user_data' => '', 'teacher_data' => '', 'add_teacher' => '', 'classify_manage' => '', 'all_classify' => '', 'course_manage' => 'current', 'required_course' => 'current', 'elective_course' => '', 'skill_course' => '', 'video_manage' => '', 'all_video' => '', 'upload_video' => '', 'order_manage' => '', 'all_order' => '', 'account_data' => '', 'feedback_manage' => '', 'all_feedback' => '', 'comment_manage' => '', 'all_comment' => '', 'link_manage' => '', 'all_link' => '', 'add_link' => '', 'activity_manage' => '', 'add_activity' => '', 'all_activity' => '');
$page_config['perpage'] = 9;
//每页条数
$page_config['part'] = 2;
//当前页前后链接数量
$page_config['url'] = '/admin/required/check';
//url
$page_config['seg'] = 4;
//参数取 index.php之后的段数,默认为3,即index.php/control/function/18 这种形式
$page_config['nowindex'] = $this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']) : 1;
//当前页
$this->load->library('mypage_class');
$page_config['total'] = count($this->required_model->query_by_check());
// file_put_contents("/home/tanxu/www/data.txt", $page_config['total']);
$this->mypage_class->initialize($page_config);
if ((int) $page_config['nowindex'] == 1) {
$data['check'] = $this->required_model->get_num_course(0, (int) $page_config['perpage'], 0);
file_put_contents("/home/tanxu/www/data.txt", print_r($data['check'], true));
} else {
$firstcount = ((int) $page_config['nowindex'] - 1) * (int) $page_config['perpage'];
$data['check'] = $this->required_model->get_num_course(0, (int) $page_config['perpage'], $firstcount);
}
$this->load->view('admin/admin_header.html', $data);
$this->load->view('admin/admin_required_check.html');
}
开发者ID:xiajb,项目名称:code32,代码行数:27,代码来源:Required.php
示例17: log
public function log($text)
{
$text = ' ' . $text . "\n" . $this->lastString;
$log = file_get_contents($this->logFile);
$log = str_replace($this->lastString, $text, $log);
file_put_contents($this->logFile, $log);
}
开发者ID:NickMitin,项目名称:FuckFrameworks,代码行数:7,代码来源:bmApi.php
示例18: execute
/**
* @see sfTask
*/
protected function execute($arguments = array(), $options = array())
{
if (count($arguments['name'])) {
$files = array();
foreach ($arguments['name'] as $name) {
$finder = sfFinder::type('file')->follow_link()->name(basename($name) . 'Test.php');
$files = array_merge($files, $finder->in(sfConfig::get('sf_test_dir') . '/unit/' . dirname($name)));
}
if ($allFiles = $this->filterTestFiles($files, $arguments, $options)) {
foreach ($allFiles as $file) {
include $file;
}
} else {
$this->logSection('test', 'no tests found', null, 'ERROR');
}
} else {
require_once __DIR__ . '/sfLimeHarness.class.php';
$h = new sfLimeHarness(array('force_colors' => isset($options['color']) && $options['color'], 'verbose' => isset($options['trace']) && $options['trace'], 'test_path' => sfConfig::get('sf_cache_dir') . '/lime'));
$h->addPlugins(array_map(array($this->configuration, 'getPluginConfiguration'), $this->configuration->getPlugins()));
$h->base_dir = sfConfig::get('sf_test_dir') . '/unit';
// filter and register unit tests
$finder = sfFinder::type('file')->follow_link()->name('*Test.php');
$h->register($this->filterTestFiles($finder->in($h->base_dir), $arguments, $options));
$ret = $h->run() ? 0 : 1;
if ($options['xml']) {
file_put_contents($options['xml'], $h->to_xml());
}
return $ret;
}
}
开发者ID:Phennim,项目名称:symfony1,代码行数:33,代码来源:sfTestUnitTask.class.php
示例19: generate
/**
* @param EntityMapping $modelMapping
* @param string $namespace
* @param string $path
* @param bool $override
* @return void
*/
public function generate(EntityMapping $modelMapping, $namespace, $path, $override = false)
{
$abstractNamespace = $namespace . '\\Base';
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$abstractPath = $path . DIRECTORY_SEPARATOR . 'Base';
if (!is_dir($abstractPath)) {
mkdir($abstractPath, 0777, true);
}
$abstracClassName = 'Abstract' . $modelMapping->getName();
$classPath = $path . DIRECTORY_SEPARATOR . $modelMapping->getName() . '.php';
$abstractClassPath = $abstractPath . DIRECTORY_SEPARATOR . $abstracClassName . '.php';
$nodes = array();
$nodes = array_merge($nodes, $this->generatePropertyNodes($modelMapping));
$nodes = array_merge($nodes, $this->generateConstructNodes($modelMapping));
$nodes = array_merge($nodes, $this->generateMethodNodes($modelMapping));
$nodes = array_merge($nodes, $this->generateMetadataNodes($modelMapping));
$nodes = array(new Node\Stmt\Namespace_(new Name($abstractNamespace), array(new Class_('Abstract' . $modelMapping->getName(), array('type' => 16, 'stmts' => $nodes)))));
$abstractClassCode = $this->phpGenerator->prettyPrint($nodes);
file_put_contents($abstractClassPath, '<?php' . PHP_EOL . PHP_EOL . $abstractClassCode);
if (file_exists($classPath) && !$override) {
return;
}
$nodes = array(new Node\Stmt\Namespace_(new Name($namespace), array(new Class_($modelMapping->getName(), array('extends' => new FullyQualified($abstractNamespace . '\\' . $abstracClassName))))));
$classCode = $this->phpGenerator->prettyPrint($nodes);
file_put_contents($classPath, '<?php' . PHP_EOL . PHP_EOL . $classCode);
}
开发者ID:saxulum,项目名称:saxulum-entity-generator,代码行数:35,代码来源:EntityGenerator.php
示例20: run_propel_build_sql_diff
function run_propel_build_sql_diff($task, $args)
{
if (!count($args)) {
throw new Exception('You must provide the application.');
}
$app = $args[0];
if (!is_dir(sfConfig::get('sf_app_dir') . DIRECTORY_SEPARATOR . $app)) {
throw new Exception(sprintf('The app "%s" does not exist.', $app));
}
run_propel_build_sql($task, $args);
pake_echo_action('propel-sql-diff', "building database patch");
define('SF_ROOT_DIR', realpath(dirname(__FILE__) . '/../../../..'));
define('SF_APP', $app);
define('SF_ENVIRONMENT', isset($args[1]) ? $args[1] : 'dev');
define('SF_DEBUG', 1);
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
$i = new dbInfo();
$i->loadFromDb();
$i2 = new dbInfo();
$i2->loadAllFilesInDir(sfConfig::get('sf_data_dir') . '/sql');
$diff = $i->getDiffWith($i2);
$filename = sfConfig::get('sf_data_dir') . '/sql/diff.sql';
if ($diff == '') {
pake_echo_comment("no difference found");
}
pake_echo_action('propel-sql-diff', "writing file {$filename}");
file_put_contents($filename, $diff);
}
开发者ID:sgrove,项目名称:cothinker,代码行数:30,代码来源:sfPropelSqlDiffTask.php
注:本文中的file_put_contents函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论