本文整理汇总了PHP中umask函数的典型用法代码示例。如果您正苦于以下问题:PHP umask函数的具体用法?PHP umask怎么用?PHP umask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了umask函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$remoteFilename = 'http://get.insight.sensiolabs.com/insight.phar';
$localFilename = $_SERVER['argv'][0];
$tempFilename = basename($localFilename, '.phar') . '-temp.phar';
try {
copy($remoteFilename, $tempFilename);
if (md5_file($localFilename) == md5_file($tempFilename)) {
$output->writeln('<info>insight is already up to date.</info>');
unlink($tempFilename);
return;
}
chmod($tempFilename, 0777 & ~umask());
// test the phar validity
$phar = new \Phar($tempFilename);
// free the variable to unlock the file
unset($phar);
rename($tempFilename, $localFilename);
$output->writeln('<info>insight updated.</info>');
} catch (\Exception $e) {
if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
throw $e;
}
unlink($tempFilename);
$output->writeln('<error>The download is corrupt (' . $e->getMessage() . ').</error>');
$output->writeln('<error>Please re-run the self-update command to try again.</error>');
}
}
示例2: getDateCatalogTree
public static function getDateCatalogTree($sPath, $data = false, $czyWyswietlacBledy = false)
{
$data = $data ? substr($data, 0, 10) : date('Y-m-d');
$data = explode('-', $data);
$oldUmask = umask(0);
if (!file_exists($sPath . $data[0] . '/')) {
if ($czyWyswietlacBledy) {
mkdir($sPath . $data[0] . '/', 0770);
} else {
@mkdir($sPath . $data[0] . '/', 0770);
}
}
if (!file_exists($sPath . $data[0] . '/' . $data[1] . '/')) {
if ($czyWyswietlacBledy) {
mkdir($sPath . $data[0] . '/' . $data[1] . '/', 0770);
} else {
@mkdir($sPath . $data[0] . '/' . $data[1] . '/', 0770);
}
}
if (!file_exists($sPath . $data[0] . '/' . $data[1] . '/' . $data[2] . '/')) {
if ($czyWyswietlacBledy) {
mkdir($sPath . $data[0] . '/' . $data[1] . '/' . $data[2] . '/', 0770);
} else {
@mkdir($sPath . $data[0] . '/' . $data[1] . '/' . $data[2] . '/', 0770);
}
}
umask($oldUmask);
return $sPath . $data[0] . '/' . $data[1] . '/' . $data[2] . '/';
}
示例3: execute
/**
* @see Console\Command\Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$module = $input->getArgument('module');
$modules = $this->moduleManager->getModules();
$path = "{$this->modulesDir}/{$module}-module";
if (isset($modules[$module])) {
$output->writeln("<error>Module '{$module}' already exists.</error>");
return;
}
if (file_exists($path)) {
$output->writeln("<error>Path '" . $path . "' exists.</error>");
return;
}
if (!is_writable(dirname($path))) {
$output->writeln("<error>Path '" . dirname($path) . "' is not writable.</error>");
return;
}
umask(00);
mkdir($path, 0777, TRUE);
file_put_contents($path . '/Module.php', $this->getModuleFile($module));
file_put_contents($path . '/composer.json', $this->getComposerFile($module));
file_put_contents($path . '/readme.md', $this->getReadmeFile($module));
mkdir($path . '/Resources/config', 0777, TRUE);
mkdir($path . '/Resources/public', 0777, TRUE);
mkdir($path . '/Resources/translations', 0777, TRUE);
mkdir($path . '/Resources/layouts', 0777, TRUE);
mkdir($path . '/' . ucfirst($module) . 'Module', 0777, TRUE);
}
示例4: up
public function up()
{
$old = umask(0);
mkdir(Config::get('upload_dir'), 0777);
umask($old);
symlink(Config::get('upload_dir'), Config::get('public_dir') . '/upload');
}
示例5: writeFile
/**
* Writes file in a save way to disk
*
* @param string $_filepath complete filepath
* @param string $_contents file content
* @return boolean true
*/
public static function writeFile($_filepath, $_contents, $smarty)
{
$old_umask = umask(0);
$_dirpath = dirname($_filepath);
// if subdirs, create dir structure
if ($_dirpath !== '.' && !file_exists($_dirpath)) {
mkdir($_dirpath, $smarty->_dir_perms, true);
}
// write to tmp file, then move to overt file lock race condition
$_tmp_file = tempnam($_dirpath, 'wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
$_tmp_file = $_dirpath . DS . uniqid('wrt');
if (!($fd = @fopen($_tmp_file, 'wb'))) {
throw new SmartyException("unable to write file {$_tmp_file}");
return false;
}
}
fwrite($fd, $_contents);
fclose($fd);
// remove original file
if (file_exists($_filepath)) {
@unlink($_filepath);
}
// rename tmp file
rename($_tmp_file, $_filepath);
// set file permissions
chmod($_filepath, $smarty->_file_perms);
umask($old_umask);
return true;
}
示例6: log_msg
/**
* log a message to file
*
* @param string $level can be error, warn, info or debug
* @param string $msg message
* @return bool true if successful, false if not
*/
function log_msg($level, $msg)
{
global $logfile;
global $loglevels;
global $request_id;
// open logfile
if ($logfile === false) {
$m = umask(0111);
// having two processes appending to the same file should
// work fine (at least on Linux)
$logfile = @fopen(LOG_FILE, 'ab');
umask($m);
}
if ($logfile === false) {
return false;
}
foreach ($loglevels as $ll) {
if ($ll == $level) {
fwrite($logfile, date('Y-m-d H:i:s') . tab() . pad($_SERVER['REMOTE_ADDR'], 15) . tab() . sprintf('%05u', $request_id) . tab() . $level . tab() . $msg . nl());
fflush($logfile);
break;
}
if ($ll == LOG_LEVEL) {
break;
}
}
return true;
}
示例7: __construct
function __construct($name)
{
global $TMP_PATH;
global $SETUP;
$dir = $TMP_PATH . "/locks";
if (!is_dir($dir)) {
if (!@mkdir($dir, 0777, true)) {
throw new ADEIException(translate("It is not possible to create lock directory \"{$dir}\""));
}
# When creating from apache, the 0777 mode is ignored for unknown reason
@chmod($dir, 0777);
}
if ($SETUP) {
$fname = $dir . "/{$SETUP}__{$name}.lock";
} else {
$fname = $dir . "/ADEI__{$name}.lock";
}
$umask = @umask(0);
$this->lockf = @fopen($fname, "a+");
if (!$this->lockf) {
@umask($umask);
throw new ADEIException(translate("It is not possible to create lock file \"{$fname}\""));
}
$fname = $dir . "/{$name}.lock";
$this->rlock = @fopen($fname, "a+");
if (!$this->rlock) {
fclose($this->lockf);
@umask($umask);
throw new ADEIException(translate("It is not possible to create lock file \"{$fname}\""));
}
@umask($umask);
}
示例8: writeCacheFile
/**
* {@inheritdoc}
*/
protected function writeCacheFile($file, $content)
{
$dir = dirname($file);
$currentUmask = umask(00);
if (!is_dir($dir)) {
if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
throw new RuntimeException(sprintf("Unable to create the cache directory (%s).", $dir));
}
} elseif (!is_writable($dir)) {
throw new RuntimeException(sprintf("Unable to write in the cache directory (%s).", $dir));
}
$success = false;
$tmpFile = tempnam(dirname($file), basename($file));
if (false !== @file_put_contents($tmpFile, $content)) {
if (false === ($success = @rename($tmpFile, $file))) {
$success = copy($tmpFile, $file);
$success = unlink($tmpFile) && $success;
}
}
if ($success) {
chmod($file, 0666);
}
umask($currentUmask);
if (!$success) {
throw new RuntimeException(sprintf('Failed to write cache file "%s".', $file));
}
}
示例9: _mkdir
/**
* Creates directory
*
* @param string $path Path to create
* @param integer $mode Optional permissions
* @return boolean Success
*/
function _mkdir($path, $mode = 0777)
{
$old = umask(0);
$res = @mkdir($path, $mode);
umask($old);
return $res;
}
示例10: buildXml
/**
* handle request and build XML
* @access protected
*
*/
protected function buildXml()
{
$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
if (!$this->_currentFolder->checkAcl(CKFINDER_CONNECTOR_ACL_FOLDER_CREATE)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_UNAUTHORIZED);
}
$_resourceTypeConfig = $this->_currentFolder->getResourceTypeConfig();
$sNewFolderName = isset($_GET["NewFolderName"]) ? $_GET["NewFolderName"] : "";
$sNewFolderName = CKFinder_Connector_Utils_FileSystem::convertToFilesystemEncoding($sNewFolderName);
if (!CKFinder_Connector_Utils_FileSystem::checkFileName($sNewFolderName) || $_resourceTypeConfig->checkIsHiddenFolder($sNewFolderName)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_INVALID_NAME);
}
$sServerDir = CKFinder_Connector_Utils_FileSystem::combinePaths($this->_currentFolder->getServerPath(), $sNewFolderName);
if (!is_writeable($this->_currentFolder->getServerPath())) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
}
$bCreated = false;
if (file_exists($sServerDir)) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ALREADY_EXIST);
}
if ($perms = $_config->getChmodFolders()) {
$oldUmask = umask(0);
$bCreated = @mkdir($sServerDir, $perms);
umask($oldUmask);
} else {
$bCreated = @mkdir($sServerDir);
}
if (!$bCreated) {
$this->_errorHandler->throwError(CKFINDER_CONNECTOR_ERROR_ACCESS_DENIED);
} else {
$oNewFolderNode = new Ckfinder_Connector_Utils_XmlNode("NewFolder");
$this->_connectorNode->addChild($oNewFolderNode);
$oNewFolderNode->addAttribute("name", CKFinder_Connector_Utils_FileSystem::convertToConnectorEncoding($sNewFolderName));
}
}
示例11: createFromImagine
/**
* @param ImageInterface $image
* @param $namespace
* @param $image_hash
* @param $image_thumb
* @return File
*/
public function createFromImagine(ImageInterface $image, $namespace, $image_hash, $image_thumb)
{
umask(00);
$dest = $this->createDestinationPath($namespace, $image_hash, $image_thumb);
$image->save($dest);
return new File($dest);
}
示例12: __construct
/**
* Initialize the Mage environment.
* @constructor
*/
public function __construct($config)
{
umask(0);
chdir($config['path']);
require_once $config['path'] . '/app/Mage.php';
\Mage::app($config['store']);
}
示例13: make_child_dir
private function make_child_dir($path)
{
// No need to continue if the directory already exists
if (is_dir($path)) {
return true;
}
// Make sure parent exists
$parent = dirname($path);
if (!is_dir($parent)) {
$this->make_child_dir($parent);
}
$created = false;
$old = umask(0);
// Try to create new directory with parent directory's permissions
$permissions = substr(sprintf('%o', fileperms($parent)), -4);
if (is_dir($path) || mkdir($path, octdec($permissions), true)) {
$created = true;
} else {
if ($permissions == '0755' && chmod($parent, 0777) && mkdir($path, 0777, true)) {
$created = true;
}
}
umask($old);
return $created;
}
示例14: loadMagento
protected function loadMagento($_languageCode = 'en')
{
if (file_exists($this->__config->get('pathToMagentoApp'))) {
include_once $this->__config->get('pathToMagentoApp');
} else {
if (file_exists(ROOT_DIR . $this->__config->get('pathToMagentoApp'))) {
include_once ROOT_DIR . $this->__config->get('pathToMagentoApp');
} else {
throw new \Exception('Mage NOT Found at ' . $this->__config->get('pathToMagentoApp'));
}
}
umask(0);
\Mage::app();
\Mage::app()->loadArea(\Mage_Core_Model_App_Area::AREA_FRONTEND);
$baseUrlMedia = \Mage::getBaseUrl(\Mage_Core_Model_Store::URL_TYPE_MEDIA);
$_stores = \Mage::app()->getStores(false, true);
if (isset($_stores[$_languageCode]) && $_stores[$_languageCode]->getIsActive()) {
$_storeID = $_stores[$_languageCode]->getId();
} else {
$_storeID = 0;
// default store for no language match
}
$this->set('languagecode', $_languageCode);
$this->set('storeid', $_storeID);
$this->set('baseurlmedia', $baseUrlMedia);
}
示例15: __construct
public function __construct()
{
$args = func_get_args();
$path = STORAGE_PATH;
// $path = isAke(get_defined_constants(), 'STORAGE_PATH', false);
if (0 == count($args)) {
return;
} elseif (2 == count($args)) {
list($db, $table) = $args;
} elseif (3 == count($args)) {
list($db, $table, $path) = $args;
}
if (false === $path) {
throw new Exception("You must provide a path in third argument of this method.");
}
if (!is_dir($path . DS . 'dbjson')) {
umask(00);
File::mkdir($path . DS . 'dbjson', 0777, true);
}
$this->dir = $path . DS . 'dbjson' . DS . Inflector::lower($db) . DS . Inflector::lower($table);
if (!is_dir($path . DS . 'dbjson' . DS . Inflector::lower($db))) {
umask(00);
File::mkdir($path . DS . 'dbjson' . DS . Inflector::lower($db), 0777, true);
}
if (!is_dir($path . DS . 'dbjson' . DS . Inflector::lower($db) . DS . Inflector::lower($table))) {
umask(00);
File::mkdir($path . DS . 'dbjson' . DS . Inflector::lower($db) . DS . Inflector::lower($table), 0777, true);
}
$changeFile = $this->dir . DS . 'change';
if (!File::exists($changeFile)) {
File::put($changeFile, '');
}
$this->db = $db;
$this->table = $table;
}