本文整理汇总了PHP中is_writable函数的典型用法代码示例。如果您正苦于以下问题:PHP is_writable函数的具体用法?PHP is_writable怎么用?PHP is_writable使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_writable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: __construct
/**
* Tests that the storage location is a directory and is writable.
*/
public function __construct($filename)
{
// Get the directory name
$directory = str_replace('\\', '/', realpath(pathinfo($filename, PATHINFO_DIRNAME))) . '/';
// Set the filename from the real directory path
$filename = $directory . basename($filename);
// Make sure the cache directory is writable
if (!is_dir($directory) or !is_writable($directory)) {
throw new KoException('Cache: Directory :name is unwritable.', array(':name' => $directory));
}
// Make sure the cache database is writable
if (is_file($filename) and !is_writable($filename)) {
throw new KoException('Cache: File :name is unwritable.', array(':name' => $filename));
}
// Open up an instance of the database
$this->db = new SQLiteDatabase($filename, '0666', $error);
// Throw an exception if there's an error
if (!empty($error)) {
throw new KoException('Cache: Driver error - ' . sqlite_error_string($error));
}
$query = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'caches'";
$tables = $this->db->query($query, SQLITE_BOTH, $error);
// Throw an exception if there's an error
if (!empty($error)) {
throw new KoException('Cache: Driver error - ' . sqlite_error_string($error));
}
if ($tables->numRows() == 0) {
// Issue a CREATE TABLE command
$this->db->unbufferedQuery('CREATE TABLE caches(id VARCHAR(127) PRIMARY KEY, expiration INTEGER, cache TEXT);');
}
}
示例3: initialize
/**
* {@inheritDoc}
*/
public function initialize()
{
if (Filesystem::isLocalPath($this->url)) {
$this->repoDir = $this->url;
} else {
$cacheDir = $this->config->get('cache-vcs-dir');
$this->repoDir = $cacheDir . '/' . preg_replace('{[^a-z0-9]}i', '-', $this->url) . '/';
$fs = new Filesystem();
$fs->ensureDirectoryExists($cacheDir);
if (!is_writable(dirname($this->repoDir))) {
throw new \RuntimeException('Can not clone ' . $this->url . ' to access package information. The "' . $cacheDir . '" directory is not writable by the current user.');
}
// update the repo if it is a valid hg repository
if (is_dir($this->repoDir) && 0 === $this->process->execute('hg summary', $output, $this->repoDir)) {
if (0 !== $this->process->execute('hg pull', $output, $this->repoDir)) {
$this->io->write('<error>Failed to update ' . $this->url . ', package information from this repository may be outdated (' . $this->process->getErrorOutput() . ')</error>');
}
} else {
// clean up directory and do a fresh clone into it
$fs->removeDirectory($this->repoDir);
if (0 !== $this->process->execute(sprintf('hg clone --noupdate %s %s', ProcessExecutor::escape($this->url), ProcessExecutor::escape($this->repoDir)), $output, $cacheDir)) {
$output = $this->process->getErrorOutput();
if (0 !== $this->process->execute('hg --version', $ignoredOutput)) {
throw new \RuntimeException('Failed to clone ' . $this->url . ', hg was not found, check that it is installed and in your PATH env.' . "\n\n" . $this->process->getErrorOutput());
}
throw new \RuntimeException('Failed to clone ' . $this->url . ', could not read packages from it' . "\n\n" . $output);
}
}
}
$this->getTags();
$this->getBranches();
}
示例4: initialize
/**
* Initializes this logger.
*
* Available options:
*
* - file: The file path or a php wrapper to log messages
* You can use any support php wrapper. To write logs to the Apache error log, use php://stderr
* - format: The log line format (default to %time% %type% [%priority%] %message%%EOL%)
* - time_format: The log time strftime format (default to %b %d %H:%M:%S)
* - dir_mode: The mode to use when creating a directory (default to 0777)
* - file_mode: The mode to use when creating a file (default to 0666)
*
* @param sfEventDispatcher $dispatcher A sfEventDispatcher instance
* @param array $options An array of options.
*
* @return Boolean true, if initialization completes successfully, otherwise false.
*/
public function initialize(sfEventDispatcher $dispatcher, $options = array())
{
if (!isset($options['file'])) {
throw new sfConfigurationException('You must provide a "file" parameter for this logger.');
}
if (isset($options['format'])) {
$this->format = $options['format'];
}
if (isset($options['time_format'])) {
$this->timeFormat = $options['time_format'];
}
if (isset($options['type'])) {
$this->type = $options['type'];
}
$dir = dirname($options['file']);
if (!is_dir($dir)) {
mkdir($dir, isset($options['dir_mode']) ? $options['dir_mode'] : 0777, true);
}
$fileExists = file_exists($options['file']);
if (!is_writable($dir) || $fileExists && !is_writable($options['file'])) {
throw new sfFileException(sprintf('Unable to open the log file "%s" for writing.', $options['file']));
}
$this->fp = fopen($options['file'], 'a');
if (!$fileExists) {
chmod($options['file'], isset($options['file_mode']) ? $options['file_mode'] : 0666);
}
return parent::initialize($dispatcher, $options);
}
示例5: prepare_dir
public static function prepare_dir($prefix)
{
$config = midcom_baseclasses_components_configuration::get('midcom.helper.filesync', 'config');
$path = $config->get('filesync_path');
if (!file_exists($path)) {
$parent = dirname($path);
if (!is_writable($parent)) {
throw new midcom_error("Directory {$parent} is not writable");
}
if (!mkdir($path)) {
throw new midcom_error("Failed to create directory {$path}. Reason: " . $php_errormsg);
}
}
if (substr($path, -1) != '/') {
$path .= '/';
}
$module_dir = "{$path}{$prefix}";
if (!file_exists($module_dir)) {
if (!is_writable($path)) {
throw new midcom_error("Directory {$path} is not writable");
}
if (!mkdir($module_dir)) {
throw new midcom_error("Failed to create directory {$module_dir}. Reason: " . $php_errormsg);
}
}
return "{$module_dir}/";
}
示例6: 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.");
}
示例7: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$realCacheDir = $this->getContainer()->getParameter('kernel.cache_dir');
$oldCacheDir = $realCacheDir . '_old';
$filesystem = $this->getContainer()->get('filesystem');
if (!is_writable($realCacheDir)) {
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
}
if ($filesystem->exists($oldCacheDir)) {
$filesystem->remove($oldCacheDir);
}
$kernel = $this->getContainer()->get('kernel');
$output->writeln(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
$this->getContainer()->get('cache_clearer')->clear($realCacheDir);
if ($input->getOption('no-warmup')) {
$filesystem->rename($realCacheDir, $oldCacheDir);
} else {
// the warmup cache dir name must have the same length than the real one
// to avoid the many problems in serialized resources files
$warmupDir = substr($realCacheDir, 0, -1) . '_';
if ($filesystem->exists($warmupDir)) {
$filesystem->remove($warmupDir);
}
$this->warmup($warmupDir, $realCacheDir, !$input->getOption('no-optional-warmers'));
$filesystem->rename($realCacheDir, $oldCacheDir);
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
sleep(1);
// workaround for windows php rename bug
}
$filesystem->rename($warmupDir, $realCacheDir);
}
$filesystem->remove($oldCacheDir);
}
示例8: __construct
/**
* Constructor.
* Requires a path to an existing and writable file.
*
* @param string $outputPath path to file to write schema changes to.
*/
public function __construct($outputPath)
{
if (!file_exists($outputPath) || !is_writable($outputPath)) {
throw new RedBean_Exception_Security('Cannot write to file: ' . $outputPath);
}
$this->file = $outputPath;
}
示例9: getStep2
public function getStep2()
{
$this->layout->step = 2;
$data['req']['php_version'] = PHP_VERSION_ID >= 50400;
$data['req']['mcrypt'] = extension_loaded('mcrypt');
$data['req']['pdo'] = extension_loaded('pdo_mysql');
if (function_exists('apache_get_modules')) {
$data['req']['rewrite'] = in_array('mod_rewrite', apache_get_modules());
}
$dirs = array($_SERVER['DOCUMENT_ROOT'] . '/apps/frontend/storage/', $_SERVER['DOCUMENT_ROOT'] . '/apps/backend/storage/', $_SERVER['DOCUMENT_ROOT'] . '/upload/', $_SERVER['DOCUMENT_ROOT'] . '/install/', $_SERVER['DOCUMENT_ROOT'] . '/apps/frontend/config/', $_SERVER['DOCUMENT_ROOT'] . '/apps/backend/config/');
foreach ($dirs as $path) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $item) {
@chmod($item, 0777);
}
}
$data['req']['wr_fr_storage'] = is_writable($_SERVER['DOCUMENT_ROOT'] . '/apps/frontend/storage/');
$data['req']['wr_bk_storage'] = is_writable($_SERVER['DOCUMENT_ROOT'] . '/apps/backend/storage/');
$data['req']['wr_upload'] = is_writable($_SERVER['DOCUMENT_ROOT'] . '/upload/');
$data['req']['wr_install'] = is_writable($_SERVER['DOCUMENT_ROOT'] . '/install/');
$data['req']['wr_fr_db'] = is_writable($_SERVER['DOCUMENT_ROOT'] . '/apps/frontend/config/');
$data['req']['wr_bk_db'] = is_writable($_SERVER['DOCUMENT_ROOT'] . '/apps/backend/config/');
$data['valid_step'] = true;
foreach ($data['req'] as $valid) {
$data['valid_step'] = $data['valid_step'] && $valid;
}
Session::put('step2', $data['valid_step']);
$this->layout->content = View::make('install::step2', $data);
return $this->layout;
}
示例10: storeEntity
/**
* Storing entity by ORM table
*
* @access public
* @return boolean
*/
public function storeEntity($buffer = null)
{
try {
// Data posted required, otherwise avoid write anything
if (!$buffer) {
throw new JMapException(JText::_('COM_JMAP_HTACCESS_NO_DATA'), 'error');
}
$targetHtaccess = null;
// Find htaccess file
if (JFile::exists(JPATH_ROOT . '/.htaccess')) {
$targetHtaccess = JPATH_ROOT . '/.htaccess';
} elseif (JFile::exists(JPATH_ROOT . '/htaccess.txt')) {
// Fallback on txt dummy version
$targetHtaccess = JPATH_ROOT . '/htaccess.txt';
$this->setState('htaccess_version', 'textual');
} else {
throw new JMapException(JText::_('COM_JMAP_HTACCESS_NOTFOUND'), 'error');
}
// If file permissions ko on rewrite updated contents
if (!is_writable($targetHtaccess)) {
@chmod($targetHtaccess, 0777);
}
if (@(!JFile::write($targetHtaccess, $buffer))) {
throw new JMapException(JText::_('COM_JMAP_ERROR_WRITING_HTACCESS'), 'error');
}
} catch (JMapException $e) {
$this->setError($e);
return false;
} catch (Exception $e) {
$jmapException = new JMapException($e->getMessage(), 'error');
$this->setError($jmapException);
return false;
}
return true;
}
示例11: dowork
function dowork()
{
$canIhaveAccess = 0;
$canIhaveAccess = $canIhaveAccess + checklevel('admin');
if ($canIhaveAccess == 1) {
if (is_writable('settings.php') == 0) {
die("Error: settings.php is not writeable.");
}
if (isset($_REQUEST['action'])) {
$action = $_REQUEST['action'];
} else {
$action = "view";
}
if ($action == "view") {
$config = new pliggconfig();
if (isset($_REQUEST['page'])) {
$config->var_page = $_REQUEST['page'];
$config->showpage();
}
}
if ($action == "save") {
$config = new pliggconfig();
$config->var_id = substr($_REQUEST['var_id'], 6, 10);
$config->var_value = $_REQUEST['var_value'];
$config->store();
}
}
}
示例12: save_future_list
public static function save_future_list($list, $save_type = FILE_APPEND)
{
$file = self::get_parent_dir() . self::$future_list_file;
$data_to_write = '';
$errors = array();
if (!file_exists($file)) {
$f = fopen($file, 'w');
if ($f === false) {
$errors['error'] = "Cannot crete future list file <code>" . $file . "</code>";
} else {
fclose($f);
}
}
foreach ($list as $el) {
$data_to_write .= trim($el['name']) . " ::: " . $el['link'] . "\n";
}
if (is_writable($file)) {
if (file_put_contents($file, $data_to_write, $save_type) == false) {
$errors['error'] = 'Cannot write to file <code>' . $file . "</code>";
}
} else {
$errors['error'] = 'File is not writable <code>' . $file . "</code>";
}
return $errors;
}
示例13: addIndexFile
private static function addIndexFile($path)
{
if (file_exists($path) || !is_writable($path)) {
return;
}
file_put_contents($path . 'index.php', '<?php header("location: ../index.php"); die;');
}
示例14: check
public function check()
{
if (phpversion() < '5.0.0') {
return Response::json(FAIL, array('您的php版本过低,不能安装本软件,请升级到5.0.0或更高版本再安装,谢谢!'));
}
if (!extension_loaded('PDO')) {
return Response::json(FAIL, array('请加载PHP的PDO模块,谢谢!'));
}
if (!function_exists('session_start')) {
return Response::json(FAIL, array('请开启session,谢谢!'));
}
if (!is_writable(ROOT_PATH)) {
return Response::json(FAIL, array('请保证代码目录有写权限,谢谢!'));
}
$config = (require CONFIG_PATH . 'mysql.php');
try {
$mysql = new PDO('mysql:host=' . $config['master']['host'] . ';port=' . $config['master']['port'], $config['master']['user'], $config['master']['pwd']);
} catch (Exception $e) {
return Response::json(FAIL, array('请正确输入信息连接mysql,保证启动mysql,谢谢!'));
}
$mysql->exec('CREATE DATABASE ' . $config['master']['dbname']);
$mysql = null;
unset($config);
return Response::json(SUCC, array('检测通过'));
}
示例15: isWritable
function isWritable($sFile, $sPrePath = '/../../')
{
clearstatcache();
$aPathInfo = pathinfo(__FILE__);
$sFile = $aPathInfo['dirname'] . '/../../' . $sFile;
return is_readable($sFile) && is_writable($sFile);
}