本文整理汇总了PHP中Dir::isWritable方法的典型用法代码示例。如果您正苦于以下问题:PHP Dir::isWritable方法的具体用法?PHP Dir::isWritable怎么用?PHP Dir::isWritable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dir
的用法示例。
在下文中一共展示了Dir::isWritable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
/**
* 往文件中添加数据
* @access public
* @param string $path
* @param mixed $data
* @param boolean $lock
* @author songdengtao <http://www.songdengtao.cn>
* @return int
*/
public static function put($path = '', $data = null, $lock = false)
{
$ret = 0;
if (!empty($path) && !is_null($data)) {
$dirPath = static::filepath2Dirpath($path);
$flag = true;
if (false === Dir::isExist($path)) {
if (false === Dir::makdir($dirPath, true)) {
$flag = false;
}
}
if (Dir::isWritable($dirPath)) {
if ($flag) {
$content = trim(var_export($data, true), "'");
$content = trim($content, '"');
$content = stripslashes($content);
$ret = file_put_contents($path, $content, $lock ? LOCK_EX : 0);
}
}
}
return $ret;
}
示例2: getProtectedStorage
/**
*
* Returns the verified storage folder. If it does not exists, it is created.
*
* @return \Mbcraft\Piol\Dir the directory, as a \Mbcraft\Piol\Dir instance, pointing to the verified storage.
* @throws \Mbcraft\Piol\IOException if the storage root does not exists or is not valid.
*
* @api
*/
public static function getProtectedStorage()
{
$protected_storage_dir = new Dir(self::$storage_root);
if (!$protected_storage_dir->exists()) {
throw new IOException("The storage folder does not exist : " . self::$storage_root);
}
if (!$protected_storage_dir->isWritable()) {
throw new IOException("The storage folder is not readable and writable : " . self::$storage_root);
}
$results = $protected_storage_dir->listElements();
if (count($results[0]) == 0 && count($results[1]) <= 1) {
if ($protected_storage_dir->isEmpty()) {
$protected_storage_dir->newRandomSubdir();
}
return $protected_storage_dir->getUniqueSubdir();
} else {
throw new IOException("The storage root folder is invalid : it must contain at most just one folder.");
}
}