FileHandler::getRealPath($source)
정의 위치
- ./classes/file/FileHandler.class.php
정의 내용
/**
* Changes path of target file, directory into absolute path
*
* @param string $source path to change into absolute path
* @return string Absolute path
*/
function getRealPath($source)
{
if(strlen($source) >= 2 && substr_compare($source, './', 0, 2) === 0)
{
return _XE_PATH_ . substr($source, 2);
}
return $source;
}
* Changes path of target file, directory into absolute path
*
* @param string $source path to change into absolute path
* @return string Absolute path
*/
function getRealPath($source)
{
if(strlen($source) >= 2 && substr_compare($source, './', 0, 2) === 0)
{
return _XE_PATH_ . substr($source, 2);
}
return $source;
}
파라메터
- string $source : 절대 경로를 알고 싶은 경로 문자열. './' 로 시작하는 경로를 입력할 경우 XE Core 의 경로를 포함해서 반환된다.
용도
- XE Core 의 index.php 위치를 기준으로한 상대 경로를 절대 경로로 변경하고 싶을 때 사용.
예제
- ./classes/file/FileHandler.class.php 파일 중 writeFile()
-
/**
* Write $buff into the specified file
*
* @param string $filename Path of target file
* @param string $buff Content to be written
* @param string $mode a(append) / w(write)
* @return void
*/
function writeFile($filename, $buff, $mode = "w")
{
$filename = self::getRealPath($filename);
$pathinfo = pathinfo($filename);
self::makeDir($pathinfo['dirname']);
$flags = 0;
if(strtolower($mode) == 'a')
{
$flags = FILE_APPEND;
}
@file_put_contents($filename, $buff, $flags|LOCK_EX);
@chmod($filename, 0644);
}
-
댓글 0