本文整理汇总了PHP中fileperms函数的典型用法代码示例。如果您正苦于以下问题:PHP fileperms函数的具体用法?PHP fileperms怎么用?PHP fileperms使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fileperms函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testChmod
/**
*
*/
public function testChmod()
{
$cache = new FileAdapter(self::$dir, new NoneSerializer(), 0777);
$cache->set('item', 'content');
$perms = fileperms(self::$dir . '/' . md5('item'));
$this->assertEquals('0777', substr(sprintf('%o', $perms), -4));
}
示例2: writeFile
/**
* Записать файл
* @param $name
* @param $content
* @throws \Exception
*/
public function writeFile($name, $content)
{
// Проыеряем, что название не пустое
if (empty($name)) {
return;
}
// Проверяем существование файла
$file_path = $this->get('kernel')->getRootDir() . $this->web_dir . $name;
if (!file_exists($file_path)) {
try {
touch($file_path);
} catch (\Exception $e) {
throw new \Exception('Не удалось создать файл ' . $name);
}
}
// Проверяем права
$file_perms = fileperms($file_path);
if ($file_perms & 0777 !== 0666) {
try {
chmod($file_path, '0666');
} catch (\Exception $e) {
throw new \Exception('Не удалось отредактировать права на файл ' . $name);
}
}
// Записываем содержимое
try {
file_put_contents($file_path, $content, LOCK_EX);
} catch (\Exception $e) {
throw new \Exception('Не удалось отредактировать файл ' . $name);
}
}
示例3: ETCoreStart
/**
* 声明模板用法
*/
function ETCoreStart($set = array('ID' => '1', 'TplType' => 'htm', 'CacheDir' => 'cache', 'TemplateDir' => 'template', 'AutoImage' => 'on', 'LangDir' => 'language', 'Language' => 'default', 'Copyright' => 'off', 'MemCache' => ''))
{
$this->TplID = (defined('TemplateID') ? TemplateID : ((int) @$set['ID'] <= 1 ? 1 : (int) $set['ID'])) . '_';
$this->CacheDir = (defined('NewCache') ? NewCache : (trim($set['CacheDir']) != '' ? $set['CacheDir'] : 'cache')) . '/';
$this->TemplateDir = (defined('NewTemplate') ? NewTemplate : (trim($set['TemplateDir']) != '' ? $set['TemplateDir'] : 'template')) . '/';
$this->Ext = @$set['TplType'] != '' ? $set['TplType'] : 'htm';
$this->AutoImage = @$set['AutoImage'] == 'off' ? 0 : 1;
$this->Copyright = @$set['Copyright'] == 'off' ? 0 : 1;
$this->Server = is_array($GLOBALS['_SERVER']) ? $GLOBALS['_SERVER'] : $_SERVER;
$this->version = trim($_GET['EaseTemplateVer']) ? die('Ease Templae E3!') : '';
//载入语言文件
$this->LangDir = (defined('LangDir') ? LangDir : (@$set['LangDir'] != 'language' && @$set['LangDir'] ? $set['LangDir'] : 'language')) . '/';
if (is_dir($this->LangDir)) {
$this->Language = defined('Language') ? Language : ($set['Language'] != 'default' && $set['Language'] ? $set['Language'] : 'default');
if (@is_file($this->LangDir . $this->Language . '.php')) {
$lang = array();
@(include_once $this->LangDir . $this->Language . '.php');
$this->LangData = $lang;
}
} else {
$this->Language = 'default';
}
//缓存目录检测以及运行模式
if (@ereg(':', $set['MemCache'])) {
$this->RunType = 'MemCache';
$memset = explode(":", $set['MemCache']);
$this->Emc = memcache_connect($memset[0], $memset[1]) or die("Could not connect!");
} else {
$this->RunType = @substr(@sprintf('%o', @fileperms($this->CacheDir)), -3) == 777 && is_dir($this->CacheDir) ? 'Cache' : 'Replace';
}
$CompileBasic = array('/(\\{\\s*|<!--\\s*)inc_php:([a-zA-Z0-9_\\[\\]\\.\\,\\/\\?\\=\\#\\:\\;\\-\\|\\^]{5,200})(\\s*\\}|\\s*-->)/eis', '/<!--\\s*DEL\\s*-->/is', '/<!--\\s*IF(\\[|\\()(.+?)(\\]|\\))\\s*-->/is', '/<!--\\s*ELSEIF(\\[|\\()(.+?)(\\]|\\))\\s*-->/is', '/<!--\\s*ELSE\\s*-->/is', '/<!--\\s*END\\s*-->/is', '/<!--\\s*([a-zA-Z0-9_\\$\\[\\]\'\\"]{2,60})\\s*(AS|as)\\s*(.+?)\\s*-->/', '/<!--\\s*while\\:\\s*(.+?)\\s*-->/is', '/(\\{\\s*|<!--\\s*)lang\\:(.+?)(\\s*\\}|\\s*-->)/eis', '/(\\{\\s*|<!--\\s*)row\\:(.+?)(\\s*\\}|\\s*-->)/eis', '/(\\{\\s*|<!--\\s*)color\\:\\s*([\\#0-9A-Za-z]+\\,[\\#0-9A-Za-z]+)(\\s*\\}|\\s*-->)/eis', '/(\\{\\s*|<!--\\s*)dir\\:([^\\{\\}]{1,100})(\\s*\\}|\\s*-->)/eis', '/(\\{\\s*|<!--\\s*)run\\:(\\}|\\s*-->)\\s*(.+?)\\s*(\\{|<!--\\s*)\\/run(\\s*\\}|\\s*-->)/is', '/(\\{\\s*|<!--\\s*)run\\:(.+?)(\\s*\\}|\\s*-->)/is', '/\\{([a-zA-Z0-9_\'\\"\\[\\]\\$]{1,100})\\}/');
$this->Compile = is_array($this->Compile) ? array_merge($this->Compile, $CompileBasic) : $CompileBasic;
$AnalysisBasic = array('$this->inc_php("\\2")', '";if($ET_Del==true){echo"', '";if(\\2){echo"', '";}elseif(\\2){echo"', '";}else{echo"', '";}echo"', '";\\$_i=0;foreach((array)\\1 AS \\3){\\$_i++;echo"', '";\\$_i=0;while(\\1){\\$_i++;echo"', '$this->lang("\\2")', '$this->Row("\\2")', '$this->Color("\\2")', '$this->Dirs("\\2")', '";\\3;echo"', '";\\2;echo"', '";echo \\$\\1;echo"');
$this->Analysis = is_array($this->Analysis) ? array_merge($this->Analysis, $AnalysisBasic) : $AnalysisBasic;
}
示例4: copy
/**
* Copies a file.
*
* If the target file is older than the origin file, it's always overwritten.
* If the target file is newer, it is overwritten only when the
* $overwriteNewerFiles option is set to true.
*
* @param string $originFile The original filename
* @param string $targetFile The target filename
* @param bool $overwriteNewerFiles If true, target files newer than origin files are overwritten
*
* @throws FileNotFoundException When originFile doesn't exist
* @throws IOException When copy fails
*/
public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
{
if (stream_is_local($originFile) && !is_file($originFile)) {
throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
}
$this->mkdir(dirname($targetFile));
$doCopy = true;
if (!$overwriteNewerFiles && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) {
$doCopy = filemtime($originFile) > filemtime($targetFile);
}
if ($doCopy) {
// https://bugs.php.net/bug.php?id=64634
if (false === ($source = @fopen($originFile, 'r'))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $originFile, $targetFile), 0, null, $originFile);
}
// Stream context created to allow files overwrite when using FTP stream wrapper - disabled by default
if (false === ($target = @fopen($targetFile, 'w', null, stream_context_create(array('ftp' => array('overwrite' => true)))))) {
throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
}
$bytesCopied = stream_copy_to_stream($source, $target);
fclose($source);
fclose($target);
unset($source, $target);
if (!is_file($targetFile)) {
throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
}
// Like `cp`, preserve executable permission bits
@chmod($targetFile, fileperms($targetFile) | fileperms($originFile) & 0111);
if (stream_is_local($originFile) && $bytesCopied !== ($bytesOrigin = filesize($originFile))) {
throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
}
}
}
示例5: loadFromFile
/**
* Load properties from a given file properties
*
* @param $file string The filename to scan
* @param $contents boolean Load the contents
* @param $loadId boolean Load id from database
* @return boolean result
*/
function loadFromFile($file, $contents = false, $loadId = false)
{
if (!JFile::exists($file) && !JFolder::exists($file . DS)) {
return false;
}
$info = @stat($file);
$this->scandate = $this->_db->getNullDate();
$this->filename = basename($file);
$this->fullpath = $file;
$this->permission = fileperms($file) & 0777;
$this->size = filesize($file);
$ctime =& JFactory::getDate($info['ctime']);
$mtime =& JFactory::getDate($info['mtime']);
$this->ctime = $ctime->toMySQL();
$this->mtime = $mtime->toMySQL();
$this->uid = $info['uid'];
$this->gid = $info['gid'];
$this->type = '';
if (is_file($file)) {
$this->type = 'file';
$this->hash_md = md5_file($file);
if ($contents) {
$f = new JD_File($file);
$this->contents = $f->read();
}
} elseif (is_dir($file)) {
$this->type = 'dir';
}
if ($loadId) {
$this->_db->setQuery('SELECT id FROM #__jdefender_filesystem WHERE fullpath = ' . $this->fullpath . ' LIMIT 1');
$this->id = $this->_db->loadResult();
}
return true;
}
示例6: setFileInformations
/**
* collect all fileinformations of given file and
* save them to the global fileinformation array
*
* @param string $file
* @return boolean is valid file?
*/
protected function setFileInformations($file)
{
$this->fileInfo = array();
// reset previously information to have a cleaned object
$this->file = $file instanceof \TYPO3\CMS\Core\Resource\File ? $file : NULL;
if (is_string($file) && !empty($file)) {
$this->fileInfo = TYPO3\CMS\Core\Utility\GeneralUtility::split_fileref($file);
$this->fileInfo['mtime'] = filemtime($file);
$this->fileInfo['atime'] = fileatime($file);
$this->fileInfo['owner'] = fileowner($file);
$this->fileInfo['group'] = filegroup($file);
$this->fileInfo['size'] = filesize($file);
$this->fileInfo['type'] = filetype($file);
$this->fileInfo['perms'] = fileperms($file);
$this->fileInfo['is_dir'] = is_dir($file);
$this->fileInfo['is_file'] = is_file($file);
$this->fileInfo['is_link'] = is_link($file);
$this->fileInfo['is_readable'] = is_readable($file);
$this->fileInfo['is_uploaded'] = is_uploaded_file($file);
$this->fileInfo['is_writeable'] = is_writeable($file);
}
if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
$pathInfo = \TYPO3\CMS\Core\Utility\PathUtility::pathinfo($file->getName());
$this->fileInfo = array('file' => $file->getName(), 'filebody' => $file->getNameWithoutExtension(), 'fileext' => $file->getExtension(), 'realFileext' => $pathInfo['extension'], 'atime' => $file->getCreationTime(), 'mtime' => $file->getModificationTime(), 'owner' => '', 'group' => '', 'size' => $file->getSize(), 'type' => 'file', 'perms' => '', 'is_dir' => FALSE, 'is_file' => $file->getStorage()->getDriverType() === 'Local' ? is_file($file->getForLocalProcessing(FALSE)) : TRUE, 'is_link' => $file->getStorage()->getDriverType() === 'Local' ? is_link($file->getForLocalProcessing(FALSE)) : FALSE, 'is_readable' => TRUE, 'is_uploaded' => FALSE, 'is_writeable' => FALSE);
}
return $this->fileInfo !== array();
}
示例7: setFolderPermissions
/**
* Set globally writable permissions on the "tmp" and "logs" directory.
*
* This is not the most secure default, but it gets people up and running quickly.
*
* @param string $dir The application's root directory.
* @param \Composer\IO\IOInterface $io IO interface to write to console.
*
* @return void
*/
public static function setFolderPermissions($dir, $io)
{
// Change the permissions on a path and output the results.
$changePerms = function ($path, $perms, $io) {
// Get current permissions in decimal format so we can bitmask it.
$currentPerms = octdec(substr(sprintf('%o', fileperms($path)), -4));
if (($currentPerms & $perms) == $perms) {
return;
}
$res = chmod($path, $currentPerms | $perms);
if ($res) {
$io->write('Permissions set on ' . $path);
} else {
$io->write('Failed to set permissions on ' . $path);
}
};
$walker = function ($dir, $perms, $io) use(&$walker, $changePerms) {
$files = array_diff(scandir($dir), ['.', '..']);
foreach ($files as $file) {
$path = $dir . '/' . $file;
if (!is_dir($path)) {
continue;
}
$changePerms($path, $perms, $io);
$walker($path, $perms, $io);
}
};
$worldWritable = bindec('0000000111');
$walker($dir . '/tmp', $worldWritable, $io);
$changePerms($dir . '/tmp', $worldWritable, $io);
$changePerms($dir . '/logs', $worldWritable, $io);
}
示例8: relocateShortcut
private static function relocateShortcut()
{
$WshShell = new COM('WScript.Shell');
$desktop = $WshShell->SpecialFolders('Desktop');
$startmenu = $WshShell->SpecialFolders('Programs');
$startmenu .= DIRECTORY_SEPARATOR . 'XAMPP for Windows';
$links = array();
$links[realpath($desktop . DIRECTORY_SEPARATOR . 'XAMPP Control Panel.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp-control.exe', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp-control.exe', 'Description' => 'XAMPP Control Panel');
$links[realpath($startmenu . DIRECTORY_SEPARATOR . 'XAMPP Control Panel.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp-control.exe', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp-control.exe', 'Description' => 'XAMPP Control Panel');
$links[realpath($startmenu . DIRECTORY_SEPARATOR . 'XAMPP Setup.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_setup.bat', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_cli.exe', 'Description' => 'XAMPP Setup');
$links[realpath($startmenu . DIRECTORY_SEPARATOR . 'XAMPP Shell.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_shell.bat', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_cli.exe', 'Description' => 'XAMPP Shell');
$links[realpath($startmenu . DIRECTORY_SEPARATOR . 'XAMPP Uninstall.lnk')] = array('TargetPath' => self::$xampppath . DIRECTORY_SEPARATOR . 'uninstall_xampp.bat', 'WorkingDirectory' => self::$xampppath, 'WindowStyle' => 1, 'IconLocation' => self::$xampppath . DIRECTORY_SEPARATOR . 'xampp_cli.exe', 'Description' => 'XAMPP Uninstall');
foreach ($links as $shortcut => $value) {
if (is_int($shortcut)) {
continue;
}
$oldfileperm = fileperms($shortcut);
if (!chmod($shortcut, 0666) && !is_writable($shortcut)) {
throw new XAMPPException('File \'' . $shortcut . '\' is not writable.');
}
$ShellLink = $WshShell->CreateShortcut($shortcut);
$ShellLink->TargetPath = $value['TargetPath'];
$ShellLink->WorkingDirectory = $value['WorkingDirectory'];
$ShellLink->WindowStyle = $value['WindowStyle'];
$ShellLink->IconLocation = $value['IconLocation'];
$ShellLink->Description = $value['Description'];
$ShellLink->Save();
$ShellLink = null;
chmod($shortcut, $oldfileperm);
}
$WshShell = null;
return;
}
示例9: addHeader
public function addHeader($size, $name)
{
$size = decoct($size);
$info = stat($this->path);
$uid = sprintf('%6s ', decoct($info[4]));
$gid = sprintf('%6s ', decoct($info[5]));
$mode = sprintf('%6s ', decoct(fileperms($this->path)));
$mtime = sprintf('%11s', decoct(filemtime($this->path)));
// Compute the "before" & "after" checksum chunks.
$before = pack('a100a8a8a8a12A12', $name, $mode, $uid, $gid, $size, $mtime);
$after = pack('a1a100a6a2a32a32a8a8a155a12', '', '', '', '', '', '', '', '', '', '');
// Compute checksum
$checksum = 0;
for ($i = 0; $i < 148; $i++) {
$checksum += ord(substr($before, $i, 1));
}
for ($i = 148; $i < 156; $i++) {
$checksum += ord(' ');
}
for ($i = 156, $j = 0; $i < 512; $i++, $j++) {
$checksum += ord(substr($after, $j, 1));
}
$checksum = sprintf('%6s ', decoct($checksum));
$checksum = pack('a8', $checksum);
$this->write($before . $checksum . $after);
}
示例10: addFileInfo
private function addFileInfo($filename)
{
$this->total[] = "#name:" . $filename . "\n";
$this->total[] = "#perm:" . fileperms($filename) . "\n";
$this->total[] = "#size:" . filesize($filename) . "\n";
$this->total[] = "\n!#start#!\n";
}
示例11: permission
function permission($filename)
{
$perms = fileperms($filename);
if (($perms & 0xc000) == 0xc000) {
$info = 's';
} elseif (($perms & 0xa000) == 0xa000) {
$info = 'l';
} elseif (($perms & 0x8000) == 0x8000) {
$info = '-';
} elseif (($perms & 0x6000) == 0x6000) {
$info = 'b';
} elseif (($perms & 0x4000) == 0x4000) {
$info = 'd';
} elseif (($perms & 0x2000) == 0x2000) {
$info = 'c';
} elseif (($perms & 0x1000) == 0x1000) {
$info = 'p';
} else {
$info = 'u';
}
$info .= $perms & 0x100 ? 'r' : '-';
$info .= $perms & 0x80 ? 'w' : '-';
$info .= $perms & 0x40 ? $perms & 0x800 ? 's' : 'x' : ($perms & 0x800 ? 'S' : '-');
$info .= $perms & 0x20 ? 'r' : '-';
$info .= $perms & 0x10 ? 'w' : '-';
$info .= $perms & 0x8 ? $perms & 0x400 ? 's' : 'x' : ($perms & 0x400 ? 'S' : '-');
$info .= $perms & 0x4 ? 'r' : '-';
$info .= $perms & 0x2 ? 'w' : '-';
$info .= $perms & 0x1 ? $perms & 0x200 ? 't' : 'x' : ($perms & 0x200 ? 'T' : '-');
return $info;
}
示例12: birth_setSave
function birth_setSave($arr, $modId)
{
global $DMC, $DBPrefix;
for ($i = 1; $i <= count($arr) / 3; $i++) {
setPlugSet($modId, "birthTitle{$i}", $arr["birthTitle{$i}"]);
setPlugSet($modId, "birthDate{$i}", $arr["birthDate{$i}"]);
setPlugSet($modId, "textColor{$i}", $arr["textColor{$i}"]);
}
//Check file visit access
$xmlFile = "../plugins/birth/birth.xml";
$os = strtoupper(substr(PHP_OS, 0, 3));
$fileAccess = intval(substr(sprintf('%o', fileperms($xmlFile)), -4));
if ($fileAccess < 777 and $os != "WIN") {
$ActionMessage = "<b><font color='red'>birth.xml => Please change the CHMOD as 777.</font></b>";
} else {
$filecontent = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$filecontent .= "<birth>\n";
for ($i = 0; $i < count($arr) / 3; $i++) {
$num = $i + 1;
if ($arr["birthTitle{$num}"]) {
$filecontent .= "\t<item>\n";
$filecontent .= "\t\t<birthTitle>" . $arr["birthTitle{$num}"] . "</birthTitle>\n";
$filecontent .= "\t\t<birthDate>" . $arr["birthDate{$num}"] . "</birthDate>\n";
$filecontent .= "\t\t<textColor>" . $arr["textColor{$num}"] . "</textColor>\n";
$filecontent .= "\t</item>\n";
}
}
$filecontent .= "</birth>\n";
$fp = fopen($xmlFile, "wb");
@fwrite($fp, $filecontent);
@fclose($fp);
$ActionMessage = "";
}
return $ActionMessage;
}
示例13: get
/**
* @param string $type
* @return KalturaTypeReflector
*/
static function get($type)
{
if (!self::$_enabled) {
return new KalturaTypeReflector($type);
}
if (!array_key_exists($type, self::$_loadedTypeReflectors)) {
$cachedDir = KAutoloader::buildPath(kConf::get("cache_root_path"), "api_v3", "typeReflector");
if (!is_dir($cachedDir)) {
mkdir($cachedDir);
chmod($cachedDir, 0755);
}
$cachedFilePath = $cachedDir . DIRECTORY_SEPARATOR . $type . ".cache";
$typeReflector = null;
if (file_exists($cachedFilePath)) {
$cachedData = file_get_contents($cachedFilePath);
$typeReflector = unserialize($cachedData);
}
if (!$typeReflector) {
$typeReflector = new KalturaTypeReflector($type);
$cachedData = serialize($typeReflector);
$bytesWritten = kFile::safeFilePutContents($cachedFilePath, $cachedData);
if (!$bytesWritten) {
$folderPermission = substr(decoct(fileperms(dirname($cachedFilePath))), 2);
error_log("Kaltura type reflector could not be saved to path [{$cachedFilePath}] type [{$type}] folder permisisons [{$folderPermission}]");
}
}
self::$_loadedTypeReflectors[$type] = $typeReflector;
}
return self::$_loadedTypeReflectors[$type];
}
示例14: nfo_setSave
function nfo_setSave($arr, $modId)
{
global $DMC, $DBPrefix;
$fieldList = array("bgcolor", "txtcolor", "imgtype");
for ($i = 0; $i < count($fieldList); $i++) {
$name = $fieldList[$i];
setPlugSet($modId, $name, $arr[$name]);
}
//Check file visit access
$configFile = "../plugins/nfo/nfo_config.php";
$os = strtoupper(substr(PHP_OS, 0, 3));
$fileAccess = intval(substr(sprintf('%o', fileperms($configFile)), -4));
if ($fileAccess < 777 and $os != "WIN") {
$ActionMessage = "<b><font color='red'>nfo_config.php => Please change the CHMOD as 777.</font></b>";
} else {
$fp = @fopen($configFile, 'r');
$filecontent = @fread($fp, @filesize($configFile));
@fclose($fp);
$filecontent = preg_replace("/[\$]imgtype\\s*\\=\\s*[\"'].*?[\"']/is", "\$imgtype = \"" . $arr['imgtype'] . "\"", $filecontent);
$filecontent = preg_replace("/[\$]bgcolor\\s*\\=\\s*[\"'].*?[\"']/is", "\$bgcolor = \"" . $arr['bgcolor'] . "\"", $filecontent);
$filecontent = preg_replace("/[\$]txtcolor\\s*\\=\\s*[\"'].*?[\"']/is", "\$txtcolor = \"" . $arr['txtcolor'] . "\"", $filecontent);
$fp = @fopen($configFile, 'wbt');
@fwrite($fp, trim($filecontent));
@fclose($fp);
$ActionMessage = "";
}
return $ActionMessage;
}
示例15: testRecursiveChmod
/**
* Tests the recursively changing of filemodes.
*/
public function testRecursiveChmod()
{
# Compile a directory name
$dir = sys_get_temp_dir() . '/wadelib';
# Delete directory from earlier runs:
FileSystemManager::rrmdir($dir);
# Create a directory
$rc = mkdir($dir);
# Create a bunch of subfiles
$files = array();
for ($i = 0; $i < 3; $i++) {
$files[] = tempnam($dir, 'wl');
}
# Switch modes
$newperm = 0777;
$rc = WadeLib::changeFilemode($dir, $newperm, true);
$this->assertEquals(true, $rc);
# Clear file status cache.
# Otherwise, during some testruns
# problems may occur with invalid
# file-permissions cached by PHP:
clearstatcache();
# Loop through created files to check filemode
foreach ($files as $f) {
$rc = fileperms($f);
echo $f, PHP_EOL;
printf('Expecting %s, got %s' . PHP_EOL, substr(sprintf('%o', $newperm), -4), substr(sprintf('%o', $rc), -4));
$this->assertEquals(substr(sprintf('%o', $newperm), -4), substr(sprintf('%o', $rc), -4));
# Unlink files
unlink($f);
}
}